My script has two variables ("quote" and "author"). It works great, but for my purposes I need to add a third variable ("class") to the quotes.txt document, and then (of course) pull it in using the PHP script. I figured this would be simple for a PHP coder, even though it's foreign to me as an HTML/CSS coder.
Here is the code...
PHP:
<?php
$file = file('quotes.txt');
$quotes = array();
$authors = array();
$count = 0;
foreach($file as $k => $v)
{
if(preg_match("#^\r?\n$#", $v) == 0)
{
$count++;
if($count % 2 == 1)
{
preg_match("#quote\:(.+)\r?\n?#i", $v, $matches);
$quotes[] = trim($matches[1]);
}
else
{
preg_match("#author\:(.+)\r?\n?#i", $v, $matches);
$authors[] = trim($matches[1]);
}
}
}
$rnd = array_rand($quotes);
$rnd_quote = $quotes[$rnd];
$rnd_author = $authors[$rnd];
echo "<p class=\"quote\">$rnd_quote</p>";
echo "<p class=\"author\">$rnd_author</p>";
?>
quotes.txt file:
quote:hello world 1
author:author 1
quote: hello world 2
author: author 2
quote: hello world 3
author: author 3
quote: hello world 4
author: author 4
Original script from: http://www.php-freebies.com/pf-random-quotes/
Hope someone can help! Thanks in advance. 🙂