Show DevBest [PHP] Random string from text [PHP]

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
The code below will show a new line of text each time the page is refreshed.
If you add more strings, change the number "2" in "$new = (rand(0,2));" to the new amount of lines.
Example: If you add a fourth line of text, change "2" to "3".

Code:
<?php
$text=array("This is the first piece of text.","This is the second piece of text.","This is the third piece of text.");
$arrlength=count($text);
$new = (rand(0,2)); //The array starts at zero, if you add more text change "2" to the new amount
  echo $text[$new]; //Echo's a random string by getting  a number from $new
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
You could also do

PHP:
<?php
$text = array("This is the first piece of text.","This is the second piece of text.","This is the third piece of text.");
$new  = rand(0, (count($text)-1)); //The array starts at zero, if you add more text change "2" to the new amount
echo $text[$new]; //Echo's a random string by getting  a number from $new
?>

...this way, you don't have to keep changing '2' etc
 

Users who are viewing this thread

Top