Jump to content

Idea i have but is it possible?


thefollower

Recommended Posts

I had the idea of randomly echo'in a certain text on a random page of the entire site... (with exlcuding lists ) so that it will show on page that the user can actually access...

 

What i was thinking was in my global include randomize what page it should be... but wondered would i have to physically hard code each page url for it to choose or is there a built in function which can scan through the root folder and pick at random?

 

And then after that find a way to do "if user is view "this url" ... echo 'stuff'"

 

?

Link to comment
https://forums.phpfreaks.com/topic/82994-idea-i-have-but-is-it-possible/
Share on other sites

<?php

$string =
'monkeys
pie
potato
grape
loser
lemonade
woot
pie';

$ex = explode("\n",$string);

shuffle($ex);

echo $ex[rand(0,count($ex))];
?>

 

Random line from the string variable. You can include a text file instead. So like:

 

<?php

$file = file('this-file.txt');

shuffle($file);

echo $file[rand(0,count($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.