| Modul: | Random Text |
| Author: | Ralf Hertsch |
| Nick: | Ralf (Berlin) |
| Contact: | hertsch@berlin.de |
| Version: | 0.1.0 |
| State: | Alpha |
| License: | GPL |
| Platform: | 2.7 |
| Last info: | 2008-10-14 |
| Rating: | |
| Download: | here |
| Forum: | here |
| Description: | A code snippet to show random text on pages.
|
| See also: | http://phpmanufaktur.de/pages/tipps-tricks/zufaelliger-inhalt.php |
Place this code in your template or on a code page:
// file with random text
$random_txt_file = 'yourfile.txt';
// intitialize random gerator
srand((double)microtime()*1000000);
if (file_exists($random_txt_file)) {
// read random text to array
$array_txt = preg_split("/ NEXT /", join('', file($random_txt_file)));
// search and display text
echo $array_txt[rand(0, sizeof($array_txt) -1)]; }
else {
echo "file for random text not found!"; }
?>
create a "yourfile.txt" file:
<p>Any text or code no 1</p>
--NEXT--
<p>Any text or code no 2</p>
--NEXT--
<p>Any text or code no 3</p>
--NEXT--
<p>Any text or code no 4</p>
--NEXT--
<p>Any text or code no 5</p>
--NEXT--
<p>Any text or code no 6</p>
and see the result:
Any text or code no 5


News-Feeder