10-21-2003, 11:35 PM
I have written a php file which when executed independantly returns exactly what I want.
I have figured that you can write html in a .php file but not php inside a .html file. (I naively tried <?php include(".... .php") ?>:) )
I suppose I'm trying to convert server side to client side in some respects, but having tried to define what it is by name that I'm trying to do, a search of this site yielded nothing nor 2 days of going through all the threads. (picked up some good tips though;) )
10-22-2003, 12:09 AM
<?php include("variables.php"); ?>
var blah = <?php echo $myvariable ?>;
I'm not too familiar with PHP, so I'm not sure if the "echo" command is needed or not. Try it both ways, and see which one does the trick.
10-22-2003, 12:25 AM
Thanks, but it won't work.
I cannot put php code inside an html document and execute it successfully.
I need to point js towards the php file without using php code inside the html.
10-22-2003, 12:36 AM
Your data has to be in quotes..
var somevariable = "<?php echo $variable?>";
wont work if $variable contains a " or a \
add this above that line:
$variable = str_replace("\\", "\\\\", $variable);
$variable = str_replace("\"", "\\\"", $variable);
10-22-2003, 12:47 AM
Doh! I really stink at PHP... :o
Thank you for that information.
10-22-2003, 10:03 AM
var myNumber = <?php echo $number_variable?>;
10-22-2003, 10:14 AM
That's okay nolachrymose, but php is worth getting to grips with. Requires a little bit of patience. Two days I've spent trying to do this and now my patience is wearing thin I have to admit.:)
mr_ego, you have cleared up a small detail which I would have left toward the end.
When I run the php file on its own I get the slash everytime theres an ' in the text. So I can use that code above to clear that up, thanks.
Here's the php file I currently have:
$mystring = 'http://www.elvisnews.com/output/dbd.asp';
$get = implode('', file($mystring)) or die('Cannot read file!');
$length = strlen ($get);
$newlength = $length - 265;
$history_output = substr($get, 16, $newlength);
$history = "<font size=2>$history_output";
I'm really pleased with myself on this one (not yet even at php novice stage).
I've managed to get a .asp from another server, managed to get rid of the standard html code it finishes with (last 265 characters
and also the first 16) and output the balance with corrected font size.
This asp file generates random quotes so everytime the php file is refreshed in the browser it changes the quote.
Here's what I tried within the html originally:
10-22-2003, 04:12 PM
Sorry Glenn, I dunno why but I didn't see your post before( must be these shades :cool: ) but thanks for contributing.
I'm gonna try this within the js within the html.
My fall back is to recreate the entire php file but using js to do it. (I think it can be done)
10-22-2003, 04:34 PM
Can't get this yet.
It is a string, not a number.
Here's what I've now tried based upon your input above:
var somevariable = "<?php include("http://www.domainname.com/phpfile.php"); ?>";
<!--This code looks like it's gonna suck something awful but I'll give anything a try once -->
<td width="146" background="image.jpg">
I'm not sure how it would get to write what I want the output from the php file to write but then again when I tried it, it doesn't do it.
You have the code from the php file in the post above.
That outputs the string $history.
From within an html document what exactly do I need to write in js to get that output ?
Apologies if I haven't been clear before, I just don't know how to explain the result I want in the right words.
10-22-2003, 05:14 PM
I'm not sure why you're going to all this trouble to try and do something that's completely impossible: HTML can't perform php include()s, and it never will be able to.
In another set of script tags (preferably with an onload function), grab your PHP-created variables and write them to the document where they belong.
10-22-2003, 05:26 PM
Well that doesn't surprise me that I've spent all this time trying to do something impossible :D
Though I did say I was aware that php files can include html but not the other way around. (I learnt that the hard way as well!!)
What you suggest sounds great.
I haven't gotta clue what you meant, but you sounded very confident and I'm sure it will work.
What's a mime thingy ?
scope, mime, other jargonny stuff, I'm not clearly out of my depth here, I've completely drowned.
I need to find the newbie room quickly so I can chat with loads of others who also don't have a clue what we're all talking about.