+ 40

Can you merge php and js in one page

Php and java script merge

18th May 2019, 8:10 PM
Rapt[#Demure] - avatar
18 Answers
+ 16
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>
18th May 2019, 8:18 PM
KrOW - avatar
+ 12
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>
19th May 2019, 5:11 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 8
19th May 2019, 9:48 PM
Sonic - avatar
+ 6
yup ... i have done tht many times... wait lame send code snipet ...
19th May 2019, 5:09 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 5
i made this for running js and return output .... just like js code play ground 😁
19th May 2019, 5:12 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 5
Yes I can Merge them in a page . <script> Your codes </script> <?pho Your codes ?>
19th May 2019, 10:27 AM
Ahmad Muhammad
Ahmad Muhammad - avatar
+ 5
Yes, you can!
19th May 2019, 5:26 PM
CodeFu - avatar
+ 3
Ys its simple
20th May 2019, 12:36 PM
海法❤️ - avatar
+ 2
19th May 2019, 3:47 PM
Nizar - avatar
+ 2
Yes it is possible
19th May 2019, 3:52 PM
Mihir Dasani
+ 2
19th May 2019, 4:55 PM
Rustamjon Muxammadjonov
Rustamjon Muxammadjonov - avatar
+ 2
Ofcourse its possible
20th May 2019, 8:53 AM
Wasi Ahamed
Wasi Ahamed - avatar
+ 2
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.
20th May 2019, 1:20 PM
+ 2
yes, you can merge PHP and is in one page.
20th May 2019, 1:50 PM
Saranya - avatar
+ 1
Cómo hago para escribir editar y guardar un programa en lenguaje Java con mi celular?
19th May 2019, 4:04 PM
Sergio Rodmm
Sergio Rodmm - avatar
You can merge PHP and Java Script and You can also add Java Script inside PHP and PHP inside Java Script
20th May 2019, 6:11 PM
Malhar Naiya
Malhar Naiya - avatar
You can Java Script in PHP as statements in echo So, it will render Java Script inside PHP
21st May 2019, 12:26 PM
Malhar Naiya
Malhar Naiya - avatar
Yep, both they all can embed to html page as scripts
22nd May 2019, 1:41 AM
An Nguyen
An Nguyen - avatar