Jump to content

[SOLVED] Displaying random lines from a text file


eMonk

Recommended Posts

I want to display thumb links randomly from a text file in php. here's a sample link:

 

<a href="../names/samantha/" class="tip thumb"><img src="../names/samantha/thumb.jpg" width="88" height="88"><span>Samantha</span></a>

 

text file will have a max of 50 lines of so. this is a temp solution until i start playing with mysql. right now im looking for a pure php solution. how can this be done? I tried the following but get the error, "Warning: array_rand() [function.array-rand]: First argument has to be an array".

 

<?php $a=file('filename.txt'); $b=array_rand($a); print($a[$b]); ?>

<?php
$image_list = file_get_contents('file.txt');

$image_list = explode("\n", $image_list);

echo array_rand($image_list);
?>

 

Warning: file_get_contents(txt) [function.file-get-contents]: failed to open stream: No such file or directory.

 

...but the file is there... any ideas?

Warning: file_get_contents(txt) [function.file-get-contents]: failed to open stream: No such file or directory.

 

...but the file is there... any ideas?

 

Check my code again, I edited it. Make sure you're passing the right file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.