Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  75] [ 2]  / answers: 1 / hits: 54869  / 12 Years ago, mon, august 13, 2012, 12:00:00

I need to write some PHP code inside a Javascript's document.write(). This is a dummy example, but in the future Javascript will generate automatically that PHP code.



This is the Hello World I have coded:



MyFile.php



<html>
<body>
<script type=text/javascript>
document.write(<?php echo Hello World; ?>);
</script>
</body>
</html>


However, nothing is displayed, and in the DOM file I get this:



<html>
<body>
<script type=text/javascript>
<!--?php echo Hello World; ?-->
</script>
</body>
</html>


Any help? Thanks


More From » php

 Answers
205

It's impossible. Php need server-side to runs, and javascript runs just on client side.
What you can do is prepare one php code to write one file and call this code by javascript.


[#83667] Sunday, August 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keyonna

Total Points: 521
Total Questions: 104
Total Answers: 96

Location: Samoa
Member since Tue, May 3, 2022
2 Years ago
;