var js_name=;alert(js_name);"."/> var js_name=;alert(js_name);".">
Home > Article > Backend Development > Can I write php in js?
PHP can be written in js, but the file must be in php file format, or have a relevant replacement execution mechanism. The code is like "3f1c4e4b6b16bbbd69b2ee476dc4f83avar js_name=20feef70ab0a35e0faba5e4b8289ac31 ;alert(js_name);2cacc6d41bbb37262a98f745aa00fbf0".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Can I write php in js?
able. If javascript is included through a js file, then the php code can also be written directly in the js file, but the extension of the included js file must be changed to php.
That is to say, you can write php in js, but the file must be in php file format, or there is a relevant replacement execution mechanism.
Example: test.php
<?php $name="百度知道 "; ?> <html> <head> <title>JS PHP 测试</title> </head> <body> <script> //js调用php var js_name=<?php echo $name;?>; alert(js_name); </script> </body> </html>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Can I write php in js?. For more information, please follow other related articles on the PHP Chinese website!