|
|
|
|
|
|
|
![]() |
#1 |
That's what she said
|
PHP pulling random line
Hi
Let's say a text document has 30 lines in it. How could PHP be used to randomly pull one of those lines, each time the web page is built? I'm looking to pull a random category or partner, or something, on my pages. PHP is not my strongest side ![]() Thanks anyhow J ![]() |
![]() |
![]() |
![]() |
#2 |
The Original Greenguy (Est'd 1996) & AVN HOF Member - I Crop Pics For Thumbs In My Sleep
|
I actually know this one!!! (not that I wrote it lol)
Code:
<?php $file = "/home/domain.com/public_html/textfile.txt"; $banners = file($file); srand((float) microtime() * 1235689); $selected = array_rand($banners); $SelBanner = trim($banners[$selected]); if ($SelBanner=="") { $SelBanner = trim($banners[0]); }; echo $SelBanner; ?> https://www.link-o-rama.com/greenguy/mlinks.htm |
![]() |
![]() |
![]() |
#3 |
That's what she said
|
It took a while before I tested it, but FYI, it works :-)
(Of course you knew it worked, I mean, it works for me too :-D ) Thanks again, appreciated J ![]() Last edited by jollyhumper; 2021-11-24 at 12:35 PM.. Reason: added [/quote] |
![]() |
![]() |
![]() |
#4 |
The Original Greenguy (Est'd 1996) & AVN HOF Member - I Crop Pics For Thumbs In My Sleep
|
...and yes I know there's useless code in there
![]() |
![]() |
![]() |
![]() |
#5 |
That's what she said
|
Thanks!
![]() I will try it as soon as I can. Hopefully this week. ![]() J ![]() |
![]() |
![]() |
![]() |
#6 |
The Original Greenguy (Est'd 1996) & AVN HOF Member - I Crop Pics For Thumbs In My Sleep
|
![]() |
![]() |
![]() |
![]() |
#7 |
Just because I don't care doesn't mean I don't understand!
Join Date: Jan 2004
Location: Poland
Posts: 91
|
<?php
$f_contents = file("random_source.txt"); $line = $f_contents[rand(0, count($f_contents) - 1)]; ?>
__________________
have phun ![]() |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | Rate This Thread |
|
|