alert(''I am the JS code embedded in PHP');";?> "."/> alert(''I am the JS code embedded in PHP');";?> ".">
Home >Backend Development >PHP Problem >Can't I write js in php?
JS code can be written in php. It is written like "alert(''I am the js code embedded in php') ;";?>".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
js cannot be written in php ?
If you want to run PHP code, you must first install the PHP operating environment. You can go to the php official website to download and install.
After the environment is set up, we can write PHP code. As shown in the picture, we create a new php file.
Open with notepad and enter the following code.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GBK" /> </head> <body> <?php echo "<script type='text/javascript'>alert(''我是嵌入php内的js代码');</script>"; ?> </body> </html>
In the code, we use the tag to embed the js code into the php file. Running this file will pop up a prompt message.
Next, we use the browser to run the php file to see if our embedded js code is successful.
Then, the browser will pop up a prompt message for us. Explanation, our embedded js code is successful!
Recommended study: "PHP Video Tutorial"
The above is the detailed content of Can't I write js in php?. For more information, please follow other related articles on the PHP Chinese website!