Jump to content

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))];
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.