andreip 0 Report post Posted March 10, 2009 Hello guys, I would need some help from you. I can't tell how to create a script (it might be PHP) to output random messages like this example : http://encide.net/ . I've googled it but I couldn't found any. Thank you in advance . Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted March 10, 2009 Here is a link to a Xisto Tutorial for using javascript to do a Quotation Rotator script.It would not be difficult to write using php either, but, I do not have time (or a need) to modify the script into php right now.http://forums.xisto.com/search.html&ate=quote+scriptSee if this will work for you. Chqnge the Array to include the quotations and see if you can get it working using JS.Post back if you have any difficulties. Share this post Link to post Share on other sites
Pankyy 0 Report post Posted March 10, 2009 (edited) You're lucky, I had that script over there: <?// change this to location of your text file$xfile = "randomthoughts.txt";$xline = file($xfile);$xline = str_replace("\n","",$xline);$xline = str_replace("\r","",$xline);srand((double)microtime()*1000000);echo $xline[rand(0,count($xline))]."<br />";?> In the randomthought.txt you have to put a 'thought' or 'phrase' per line and that's it. Edited March 10, 2009 by Pankyy (see edit history) Share this post Link to post Share on other sites
pasten 0 Report post Posted March 11, 2009 (edited) Now you are even more luckier Andrie. Not long back I too coded this type of script. You can find the detailed tutorial here:http://forums.xisto.com/topic/62062-php-fetching-random-line-from-a-text-file-and-displaying-it-using-ajaxiframe/I did those for one of my friend. There are two versions of it, one using AJAX and the other using iframe (if javascript disabled). The examples can be seen here:Random line fetcher using AJAXRandom line fetcher using iframeI have basic un-styled versions too in that tutorial. Check that if you only want to see the code. The main php code is: <?phpsrand ((double)microtime()*1000000);$f_contents = file ("did-you-know.txt");$line = $f_contents[array_rand ($f_contents)];print $line;?> If you want to just keep it simple, you can use either of the core code (Pankyy's or mines) without any AJAX or iframes. Hope that helps.Jlhaslip you actually told about a tutorial link, but the link is a search result giving error page. Check that out. Edited March 11, 2009 by pasten (see edit history) Share this post Link to post Share on other sites
andreip 0 Report post Posted March 11, 2009 Wow guys you are all 3 awesome. I searched it a lot and didn't find it. And believe me when I search I really search .Well I'll try them out and if there is anything I should post. Thank you again for your help ! Share this post Link to post Share on other sites
flashy 0 Report post Posted March 11, 2009 Sorry i didn't see this topic earlier - but Xisto has been down for days on end for me I made an easy cut and paste if you want to use it - it just uses a random number from an Array and outputs it - very simple and little code. <?php // Simply add more onto $text = array( 'hello', 'goodbye', 'morning', 'i like cheese' ); // Count values $vals = count($text); // Set random number $rand = rand(0, $vals - 1); // Echo the text, with a random value echo $text[$rand];?> Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted March 11, 2009 flashy,Good job.Check out this page at php.net for an even better approach to the random array selection.http://ca3.php.net/manual/en/function.array-rand.phpShould be able to use it instead of your code. Using the in-built php functions are typically faster and less demanding on the server. <?php // Simply add more onto $text = array( 'hello', 'goodbye', 'morning', 'i like cheese' ); echo $text[array_rand( $text )];?> Share this post Link to post Share on other sites