I have a file ‘quotes.php’ (code below) that calls up a random quotation from a separate text file called ‘quotes.txt’. It works fine. But… I’d like to have just one ‘quotes.txt’ at a specific url, say http://www.mysite.com/quotes.txt’ where it can be accessed through ‘quotes.php’ on several different sites hosted on different servers.
I suspect I simply need to change the line “$file = “quotes.txt”;” to make the location a url, but I do not know how to do this. Thanks for some assistance!
<?
$file = "quotes.txt"; // Alter if not in server root
// Do not edit below
$x = 1;
if (file_exists($file)) {
$text = fopen($file, "r");
if ($text) {
while(!feof($text)) {
$str[$x] = fgets($text);
$x++;
}
}
fclose($text);
}
else {
die("Data file does not exist");
}
$top = $x-3;
$ct = rand(0, $top);
if ($ct==0) {
$ct=1;
}
if (!$str[$ct]) {
while (!$str[$ct]) {
$ct = rand(0, $top);
if ($ct==0) { $ct=1; }
}
}
echo "<b> <i>$str[$ct]</i></b>";
?>