Home > Backend Development > PHP Problem > Can't I write js in php?

Can't I write js in php?

藏色散人
Release: 2023-03-13 21:42:01
Original
2970 people have browsed it

JS code can be written in php. It is written like "alert(''I am the js code embedded in php') ;";?>".

Can't I write js 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.

Cant I write js in php?

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=&#39;text/javascript&#39;>alert(&#39;&#39;我是嵌入php内的js代码&#39;);</script>";
?>
</body>
</html>
Copy after login

Cant I write js in php?

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.

Cant I write js in php?

Next, we use the browser to run the php file to see if our embedded js code is successful.

Cant I write js in php?

Then, the browser will pop up a prompt message for us. Explanation, our embedded js code is successful!

Cant I write js in php?

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template