...

View Full Version : php in javascript



asherinho
08-01-2008, 08:48 AM
Whats up guys! I am trying to figure out how I can embed PHP codes in javascrip page but I cant find the way.can you halp me if there is any way

abduraooft
08-01-2008, 08:59 AM
<script type="text/javascript">
<?php
echo "alert('hello')";
?>
</script>

asherinho
08-01-2008, 09:05 AM
That one I know,but the thing is I have a page saved in .js extension and I want to embed php in it.is it going to work that way?

abduraooft
08-01-2008, 10:26 AM
Save your script file with a php extension, say myfile.js.php and then add a php header at the beginning, like

<?php
header('Content-type: application/javascript');
?>
alert('<?php echo "hello";?>');
<?php
echo "alert('another hello :)')"
?>

Now
<script type="text/javascript" src="myfile.js.php"></script> should work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum