Hello Freinds, I want to echo this javascript on php page. i need to echo this. can some one help me please. thanks Alvin
<? echo " <script><br /> image_id = "123456"<br /> image_src="./$path" . $id . ";<br /> </script><br /> <script src="http://www.mysite.com/code.js"></script><br /> <noscript></noscript>"; ?> or <? echo "<script> image_id = \"123456\" image_src=\"./$path" . $id . \"; </script> <script src=\"http://www.mysite.com/code.js\"></script> <noscript></noscript>";?> First one will display the code in browser, second one will execute the javascript.
Try this <?php echo "<script> image_id = \"123456\" image_src=\"./$path".$id."; </script> <script src=\"http://www.mysite.com/code.js\"></script> <noscript></noscript>"; ?> Code (markup):
echo '<script> image_id = "123456" image_src= "./$path' . $id . '"; </script> <script src="http://www.mysite.com/code.js"></script> <noscript></noscript>'; PHP: That should work
try this but i really don't know if it'll change anything but i would give it a try $foo='<script> image_id = "123456" image_src= "./$path' . $id . '"; </script> <script src="http://www.mysite.com/code.js"></script> <noscript></noscript>'; echo ' <script> eval('.$foo.'); </script>';
^^ $path is between single quotes and won't be parsed. Then why on earth are you eval'ing the JavaScript? And eval() won't work with the <script> tags inside... Try this. <?php echo '<script type="text/javascript"> image_id = "123456"; image_src= "./' . $path . $id . '"; </script> <script type="text/javascript" src="http://www.mysite.com/code.js"></script> <noscript></noscript>'; ?> PHP:
well i had few cases when js didn't work when parsed with php. I used eval and then it worked Oh yeah and yeah it should be without script tags