![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Registered User
Join Date: Mar 2003
Posts: 13
|
PHP Question
I've been using the below php script to randomly take a single line from the file test.txt and insert it into a webpage.
Could someone tell me how I could add a variable X to this script so that I can set it to whatever I want, eg x=5. In this case, the script would take 5 lines from test.txt and insert it into a webpage. Thanks <?php $file = "test.txt"; $file_Content = file($file); if (count($file_Content) > 0) { $line = $file_Content[rand(0,count($file_Content)-1)]; echo $line; } ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 | |
Confirmed User
Join Date: Mar 2003
Posts: 365
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 735
|
PHP Code:
Hit me up @ 227230257 and ill help ya if im around ![]()
__________________
lol internet. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 | |
Confirmed User
Join Date: Jan 2003
Location: United States of America
Posts: 1,159
|
Quote:
<?php $x = 5; // Your X variable $file = "test.txt"; $file_Content = file($file); if (count($file_Content) > 0) { for($i=0;$i<$x;$i++){ $line = $file_Content[rand(0,count($file_Content)-1)]; echo $line; } } ?> |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Will code for food...
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
|
$file_Content = file("test.txt");
if (count($file_Content) > 0) for($i=0;$i<5;$i++) echo $file_Content[rand(0,count($file_Content)-1)]; short version ![]()
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Registered User
Join Date: Mar 2003
Posts: 13
|
Quote:
Thanks, this works well. Two things I thought of after running your script. 1. How can I avoid duplicate lines being taken from test.txt. I'd like X number of lines, all are different. 2. How to add a break between the lines of data so that each line of text from test.txt is on it's own line. Currently the output is as follows: google yahoo google altavista msn Would like it as (note there are no duplicates and each is on it's own line): lycos yahoo altavista msn Thanks |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
So Fucking Banned
Join Date: Aug 2003
Location: San Diego, CA
Posts: 5,464
|
That code looks familiar
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |