Home  >  Article  >  Backend Development  >  What should I do if the alert function is garbled when using JavaScript in PHP?

What should I do if the alert function is garbled when using JavaScript in PHP?

coldplay.xixi
coldplay.xixiOriginal
2020-07-10 15:25:182427browse

The solution to the garbled alert function when using JavaScript in PHP: 1. Specify the character set in the html language and use the [] tag; 2. Check the encoding method of the file; 3. Use the echo function to output.

What should I do if the alert function is garbled when using JavaScript in PHP?

Solution to the garbled alert function when using JavaScript in PHP:

1. Specified characters in html language Set, use the tag

Example:
     <html>
         <head>
           <title>编码那点事</title>
           <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        </head> 
    </html>

2. Check the encoding method of the file

Take Dreamwaver CS4 as an example, look at the logo in the lower right corner

What should I do if the alert function is garbled when using JavaScript in PHP?

Just save it as the same encoding method you specified. This is often easily overlooked.

3. Similar to specifying the encoding method in programming languages ​​​​such as php, using the echo function to output (I found that the echo function has other powerful functions besides output. It can be used as a function return value in JQuery and Ajax. So far, I I still think this is a magical use)

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

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of What should I do if the alert function is garbled when using JavaScript in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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