Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP代码返回特殊德语字符的HTML实体_Php_Mysql_Character Encoding_Jquery Ui Autocomplete - Fatal编程技术网

PHP代码返回特殊德语字符的HTML实体

PHP代码返回特殊德语字符的HTML实体,php,mysql,character-encoding,jquery-ui-autocomplete,Php,Mysql,Character Encoding,Jquery Ui Autocomplete,我无法让我的PHP5.3代码返回MySQL 5.5DB中的内容 我使用的是jQueryUIAutoComplete1.9.2,但它也使用了1.8.x来检索城市名称。例如,一个城市是Heßheim,但PHP正在返回Heß;嗨。数据库/表排序规则是Latin1_general_ci,但将其更改为utf8_general_ci没有帮助。我的PHP代码: $term = trim(strip_tags($_GET['term'])); //retrieve the search term th

我无法让我的PHP5.3代码返回MySQL 5.5DB中的内容

我使用的是jQueryUIAutoComplete1.9.2,但它也使用了1.8.x来检索城市名称。例如,一个城市是Heßheim,但PHP正在返回Heß;嗨。数据库/表排序规则是Latin1_general_ci,但将其更改为utf8_general_ci没有帮助。我的PHP代码:

$term = trim(strip_tags($_GET['term']));
//retrieve the search term that autocomplete sends

if (!is_numeric($term)) {
    $qstring = "SELECT DISTINCT city FROM table WHERE city LIKE '" . $term . "%' ORDER BY city ASC";
    $result = mysql_query($qstring);
    //query the database for entries containing the term

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //loop through the retrieved values
        //$row['id'] = (int)$row['id'];
        $row['city'] = htmlentities(strip_tags($row['city']));
        $row_set[] = htmlspecialchars_decode($row['city']);
        //build an array
    }
}

header('Content-Type: text/html; charset=utf-8');
echo json_encode($row_set);
我已经尝试了所有我能想到的方法来解码HTML实体,但即使是上面的方法也不能做到。另外,$row['city']=htmlentiestrip_标记$row['city'];必须在那里,否则他就什么也回不来了

测试脚本将返回此网页-[Heddesheim,Heidelberg,Heßheim]——页面源代码如下-[Heddesheim,Heidelberg,Heß;heim]。当然jqueryuiautocomplete将其列为Heß;您好。

您应该使用html实体解码而不是html特殊字符解码

还有,如果你只是对它进行编码,为什么还要对它进行解码?浏览器将在呈现页面时解码实体,因此我认为您只需要

$row['city'] = htmlentities(strip_tags($row['city']));  
$row_set[] = $row['city'];

您是如何将其设置为UTF-8的?您是否都将连接设置为UTF-8,并确保数据库中的数据位于UTF-8中?请尝试添加以下内容:mysql_query'set NAMES utf8';在你对数据库做任何事情之前。我目前把MySQL连接、数据库和表都设置为utf8\u general\u ci。我只是尝试添加MySQL\u查询“set NAMES utf8”;在建立了db连接之后,现在我得到了[Heddesheim,Heidelberg,He\u00dfheim],而不是[Heddesheim,Heidelberg,Heß;heim]。好的,当我将htmlspecialchars_decode与html_entity_decode交换时,对于Heßheim所在的特定城市,我得到了null返回。另外,这对我来说是一件令人困惑的事情——我认为htmlentities在某种意义上是在解码,没有它,jquery autocomplete根本不会列出任何城市;嘿,不用解码就试试,直接储存。输出是什么?如果保存脚本的文件在UTF-8中,没有BOM,那么这应该可以工作,连同HTML页面,脚本和页面都应该在UTF-8中保存,没有BOM,而不仅仅是用代码声明。好的,你只是超出了我的能力。。。什么是BOM?我如何知道脚本和页面是否都保存在UTF-8中而没有BOM?同样,这是正确的-Heßheim是它在DB中的存储方式。也许我应该补充一点,我正在使用phpMyAdmin来管理数据库,所以当我查看它时,phpMyAdmin可能正在解码德语字符,因此这意味着它并没有按照我认为的方式进行存储?phpMyAdmin做得很好。告诉我你使用的是什么文本编辑器或IDE,我可能会帮助你如何在特定的编码方案中保护文件。我正在Ubuntu 12.04笔记本上使用Aptana Studio 3.3.1。我刚刚检查了一下,在编辑下有一个选项可以设置编码,它被设置为UTF-8。