0

How to add php code in a javascript function?

16th Dec 2016, 3:35 AM
Jumar Hamac
Jumar Hamac - avatar
2 Answers
+ 2
It's not possible. JavaScript is a client-side language. PHP is a server-side language. For security reasons among others, JavaScript cannot use PHP. However, as a substitute, you can call another page that uses PHP. @Kamil, the PHP part is automatically removed when ran and then you're just left with the string. No real PHP operations can be performed with that method.
16th Dec 2016, 3:46 AM
Ben
Ben - avatar
+ 2
you could write this js code: document.write (" <?php echo "text"; ?> ") this will execute the php code via js of course this won't work if you are not on a server with php installed
16th Dec 2016, 6:22 AM
Kamil
Kamil - avatar