When I wrote a PHP script to access the database today, I found that the Chinese strings are stored in HTML encoding (for example, the HTML code corresponding to the Chinese character "Mao" is "& #27611; "), so that the field cannot be queried in Chinese, but it must be converted to encoding before condition matching.
The htmlentities and html_entity_decode functions must be used for conversion between readable and HTML characters in PHP. Write the following query statement,
Code
$ SQL = " Select ID, depart_name, first_name, last_name, local_name, extension, mobile, title " ;
$ SQL . = " From pb_extension E, pb_department d " ;
$ SQL . = " Where E. depart_id = D. depart_id " ;
$ SQL . = " And D. Plant =' " . $ Plant . " ' " ;
$ SQL . = " And (first_name like '% " . $ Http_post_vars [ " Q " ] . " %' " ;
$ SQL . = " Or last_name like '% " . $ Http_post_vars [ " Q " ] . " %' " ;
$ SQL . = " Or local_name like '% " . Htmlentities ( $ Http_post_vars [ " Q " ]) . " %' " ;
$ SQL . = " Or extension like '% " . $ Http_post_vars [ " Q " ] . " %' " ;
$ SQL . = " Or mobile like '% " . $ Http_post_vars [ " Q " ] . " %' " ;
$ SQL . = " Or depart_name like '% " . $ Http_post_vars [ " Q " ] . " %' " ;
$ SQL . = " Or title like '% " . $ Http_post_vars [ " Q " ] . " %' " ;
$ SQL . = " ) " ;
And execute. This statement can be correctly executed and queried in SQL analyzer. However, the execution of this script in IE prompts that the query result is zero. Why?
After carefully checking this SQL section and checking the source code in IE, we found the root cause of the problem. The query value is converted to HTML encoding by using the htmlentities function. This encoding contains special characters (such as the example in the first section). This character has another meaning in IE. In IE, "& amp;" is generally used to represent this symbol. As a result, the output SQL statement in IE is different from the actually executed statement.
To solve this problem, we must try to prevent ie from using the "& amp;" symbol to indicate. After one query, it is found that the followingCodeThis problem can be solved.
Code
<? PHP
$ Trans = Get_html_translation_table (Html_entities );
$ Trans = Array_flip ( $ Trans );
$ Encoded = " Hallo & amp; & lt; Frau & gt; & amp; Kr & auml; mer " ;
$ Original = Strtr ( $ Encoded , $ Trans );
Echo $ Original ;
?>
Run this code and the output $ original variable value is "Hallo & <Frau> & kr ämer". This is the result I want.
The above are the problems and solutions I encountered at work. I wrote them on my blog and shared them with my friends who encountered similar problems.