Home > Backend Development > PHP Problem > What should I do if a garbled window pops up when executing the alert() function in the PHP page?

What should I do if a garbled window pops up when executing the alert() function in the PHP page?

王林
Release: 2023-02-28 20:18:01
Original
2623 people have browsed it

What should I do if a garbled window pops up when executing the alert() function in the PHP page?

Problem description:

The encoding method of the PHP page is utf-8. When the following code is output, a garbled window pops up.

echo "<script type=&#39;text/javascript&#39;>alert(&#39;已全部清除!&#39;);script>";
Copy after login

Solution:

Because alert() outputs Chinese to the browser, you must specify the encoding method as UTF-8 in the web page, that is,

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Copy after login
Copy after login

Note: If the PHP page encoding method is gb2312, there is no need to add

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Copy after login
Copy after login

For more related tutorials, please visit php Chinese website.

The above is the detailed content of What should I do if a garbled window pops up when executing the alert() function in the PHP page?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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