1

我不知道这是怎么回事,但 htmlentities() 函数不起作用!

这是我所做的

(底部代码可以正常工作,但 htmlentities() 不会将引号转换为 html 代码!例如 " 应该更改为一些 html5 代码!

$term = "'" . addslashes($_GET['search_term']) . "%'";
if(!isset($term{2})){
    exit();
}

$query = $db->query('SELECT customerID, fullName, dID, birthYear, homeAddress, ID, DATE_FORMAT(idIssue, "%d-%m-%Y") AS idIssue, DATE_FORMAT(idExp, "%d-%m-%Y") AS idExp, phone
                     FROM customers WHERE (fullName LIKE '.$term.' ) LIMIT 0,10');



while( $row = $query->fetch_assoc()){

    foreach($row as $key => $value){
        $arr[$key] = htmlentities(stripslashes($value), ENT_QUOTES);
    }
    $json[] = $arr;
}

echo json_encode($json);
4

1 回答 1

6

您传递给 json_encode() 的值必须是 UTF-8 编码数据。因此,在运行之前json_encode,请使用utf8_encode.

例子:

 $arr[$key] = htmlentities(stripslashes(utf8_encode($value)), ENT_QUOTES);
于 2013-02-01T03:51:56.237 回答