View Full Version : using php includes inside javascript?
Ankun
11-18-2002, 06:00 AM
Ok..I know this has got to be SOooo simple, just my stupidity is disabling me from figuring this out, I have a variable in javascript, and inside this variable I want to use a php include..does anyone know how exactly I would go about doing this?
I've tried using <?php include('url'); ?> but it seems javascript doesnt like the ";" and when i remove it php gets pissed ;) sooo yeh...
glenngv
11-18-2002, 06:30 AM
i dont know PHP but does include return something that you set a javascript variable to have this value?
Ankun
11-18-2002, 06:40 AM
yes, it displays the content of a different page inside this variable, and It has nothing to do with the variable spanning more than one line, I formatted the page that was to be included to all go in one line.
glenngv
11-18-2002, 07:01 AM
can you post the generated code?
Garadon
11-18-2002, 07:16 AM
try this
var variable1=<?include('url');?>;
Ankun
11-18-2002, 08:07 AM
yeh the javascript code goes like this:
<script language="javascript">
var content=new Array()
content[0]='Content 1'
content[1]='Content 2'
content[2]='Content 3'
</script>
and uh what I want to do is change content[0]='content 1' to
content[0]='include code to content1'
and uh..when I use a semicolon to end the php include javascript gives me an error saying expected end of statement..which it should, and when i take the semicolon out php tells me its a parse error, which should happen too, basically what I am trying to do is figure out how to use the php include without the semicolon..I was considering declaring a variable to write the hex code for a semicolon..but uh..first I dont even know if javascript supports it, and second I wouldnt know how to include that into my script.
edit: damn I should either feel smart or stupid..but I figured it out, this was soooo amazingly simple..far more than I ever suspected ;)..I just dont have php installed on my computer, lol. That would explain why I got the errors I did..
Try the universal escape character \
var varname = '<?php include(\'filename.php\')\;';
Just read your last reply - :) 'tis often helpful to have php running if you want it parsed :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.