Ok i have a php file which when refresh it changes the quote http://www.geekazoid.co.uk/QOTDS.php I would like to put this in javascript so other websites can use on there pages. Yes the <?php include > Thing would work but i dont want them to have to use php and i know javascript works in .html so is there anyway i can do this .... ? I know this website does it >> http://www.quotedb.com/random_quotes_generator So does anyone know how to do this ? Thanx alot
The php file you point your JS at must output JS. So, you'd have to re-code your PHP file. All the current output from your PHP file needs to be in an html file, for instance, and where you want the quote to appear, you put the JS that calls the php file that outputs the JS to write your quote. In short, yes, you can do that.
In looking at the example web site you gave that is doing this function now, they are adding a reference to a php page that will output javascript. What you would need to do is make a page in PHP, but instead of it's output being html with the quote, it would have to output what the content of a .js file would look like, with the javascript inside. You may have to remove some headers from the output. What you might want to do is make a static .js file that puts out just one quote - the same one every time. Then, create a page with the include script that you are going to give out, and include that js file. Once you get it to work, create a dynamic PHP page that makes an output exactly like your .js file, except with different quotes in it each time. Then change your include text that you give out to people to reference that PHP file instead of the static .js file that you had. Hope that makes sense.
im sorry i didnt understand that... would it be possible to make that a bit clearer im a bit thick . sorry
Your PHP script would look like this: <?php // generate random quote $random_quote (from database / file) echo "document.write('" . str_replace("'", "\'", $random_quote) . "');"; ?> PHP: Output: document.write('Example \'quote\'.'); Code (markup): and that's basically Javascript file. After that you can use it on other pages: <script language="javascript" src="http://www.geekazoid.co.uk/QOTDS.php"></script> Code (markup):
Brilliant that looks perfect, im going to make myself look stupid here but what do i do with that script ? I mean how do i use it... do i edit the top bit ?