php pdo和html实体解码 [英] php pdo and html entity decode

查看:57
本文介绍了php pdo和html实体解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按如下所示转义后将数据插入数据库:

The data was inserted into the database after being escaped as follows:

$caller=htmlentities($formVarsI['caller'], ENT_QUOTES, "UTF-8");

某些$ caller带有单引号,例如O'Connor,这些在数据库中看起来像O ' Connor.

Some of the $caller's have single quotes e.g. O'Connor and these then look like O'Connor in the database.

我现在正尝试使用REST API提取数据,以下是我的php:

I am now trying to extract the data using a REST api and below is my php:

$sql = "SELECT caller FROM tbl_calls ";
try {
    $db = getConnection();
    $stmt = $db->query($sql);  
    $calls= $stmt->fetchAll(PDO::FETCH_OBJ);
    $db = null;
    echo json_encode($calls);
    }

我的问题是如何在$ caller上进行html_entity_decode以便删除

My question is how to html_entity_decode on $caller so as to remove the

'

适用于它适用的每个呼叫者.注意有大约.数据库中有10,000个条目.

for each caller where it applies. Note there are approx. 10,000 entries in the db.

推荐答案

我认为您应该指定quotes参数.

I think you should specify the quotes parameter.

html_entity_decode('O'Connor', ENT_QUOTES);
// output: O'Connor

默认情况下为ENT_COMPACT,它仅转换双引号,而不是单引号.

By default it's ENT_COMPACT and it just convert double quotes, not single.

这篇关于php pdo和html实体解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆