php - 如何将 & 转换为出现在自动完成下拉列表中的 &

标签 php mysql

在我的自动完成下拉搜索中 '&' 显示为 '&' 如何将其保持为 '&'

这是我的下拉php代码

$term = trim(strip_tags($_GET['term']));
$term = str_replace(' ', '%', $term);
$qstring = "SELECT name as value, client_id FROM goa WHERE name LIKE '" . $term . "%' limit 0,5000";
$result = mysql_query($qstring);
$qcount = 0;
if ($result) {
    while ($row = mysql_fetch_array($result)) {
        $row['value'] = htmlentities(stripslashes($row['value']));
        $row['id'] = (int) $row['client_id'];
        $row_set[] = $row; //build an array$qcount= $qcount + 1;}}echo json_encode($row_set); //format the array into json data
    }
}

最佳答案

要从字符串中删除 &,您可以使用 html_entity_decode

while ($row = mysql_fetch_array($result)) {
        $row['value'] = html_entity_decode($row['value']);
        $row['id'] = (int) $row['client_id'];
        $row_set[] = $row; 
    }

关于php - 如何将 & 转换为出现在自动完成下拉列表中的 &,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31800990/

相关文章:

php - 如何在 PHP 文件中使用 etags?

php - 如何对复杂的XML文档进行签名?

javascript - 将数据发布到页面并同时打开该页面

php - 制作 PHP/MySQL 搜索引擎

MySQL:char_length(),俄语值错误

PHP:ZipArchive::close():重命名临时文件失败:没有这样的文件或目录

mysql - 两个表的左外连接

c# - 在 C# 应用程序中隐藏 MySQL 凭据

mysql - 将缩写字符串格式的日期转换为mysql中的日期格式

php - 使用 bootstrap datetimepicker 在 cakephp 3.x 中无法正确保存 DateTime