Can you merge php and js in one page

Php and java script merge

5/18/2019 8:10:56 PM

Rapt [#demure]

18 Answers

New Answer


PHP is nothing more than a program than return one page to browser and nothing deny to put js code in it. Example: <?php echo "<b>From PHP</b>" ?> <script> alert('JS'); </script>


here is that <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <script> try{ <?php if(isset($_REQUEST['script'])){ if(empty($_REQUEST['script'])){ echo 'document.body.innerHTML+="empty value provided <br>"'; }else{ echo $_REQUEST['script']; } }else{ echo 'document.body.innerHTML+="no output<br>"'; } ?> }catch(e){ document.body.innerHTML+=e; } </script> </body> </html>




yup ... i have done tht many times... wait lame send code snipet ...


i made this for running js and return output .... just like js code play ground 😁


Yes I can Merge them in a page . <script> Your codes </script> <?pho Your codes ?>


Yes, you can!


Ys its simple




Yes it is possible



Ofcourse its possible


As many others here stated already, you can easily do that. Just note that it's bad practice per most industry standards though and you should keep JS/PHP in their own separate files outside of your HTML structure then link them in by proper means. If industry standards aren't your concern, by all means, do whatever you want. lol If it turns into a big project, you'll thank yourself later for keeping it clean/organized/separate in the long run.


yes, you can merge PHP and is in one page.


Cómo hago para escribir editar y guardar un programa en lenguaje Java con mi celular?


You can merge PHP and Java Script and You can also add Java Script inside PHP and PHP inside Java Script


You can Java Script in PHP as statements in echo So, it will render Java Script inside PHP


Yep, both they all can embed to html page as scripts