Jump to content
xisto Community
andreip

Script Help I could use some help into a script. Please enter.

Recommended Posts

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 :D.

Share this post


Link to post
Share on other sites

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+script

See 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

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 by Pankyy (see edit history)

Share this post


Link to post
Share on other sites

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 AJAX

Random line fetcher using iframe

I 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 by pasten (see edit history)

Share this post


Link to post
Share on other sites

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 :D.Well I'll try them out and if there is anything I should post. Thank you again for your help :D!

Share this post


Link to post
Share on other sites

Sorry i didn't see this topic earlier - but Xisto has been down for days on end for me :D

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

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.php

Should 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.