如何在php中从fetch_object的返回值中删除特殊字符



我在MySQL数据库中遇到了克服特殊字符的挑战。

$stmt = $con->prepare("SELECT * FROM my table");
$stmt->bind_param("s",$parameter);
$stmt->execute();

$result = $stmt->get_result();

$resultArray=array();

while($row = $result->fetch_object())
{
//echo json_encode($row); **This statement always returning right data.**
array_push($resultArray,$row);
}
echo json_encode($resultArray); //This statement returns nothing when any of the data have special characters

我该如何克服这一点?有没有一种方法可以从$row的返回值中转义special?

$行的返回位于对象下方

[{"ID":13,"ClassName":"4,5","QuestionName":"Who discovered telephone?","Option1":"Albert - Einstein","Option2":"Newton","Option3":"Alexander Grahambell","Option4":"Thomas Alva Edison","RightOption":3,"Duration":60,"IsRegionSpecific":0,"VideoReference":"","Explanation":""}]

这对我的array_map('utf8_encode',$row(有效

$stmt = $con->prepare("SELECT * FROM mytable");
$stmt->bind_param("s",$myparam);
$stmt->execute();

$result = $stmt->get_result();

$resultArray=array();

while($row = $result->fetch_array())
{
**$row = array_map('utf8_encode', $row);**
array_push($resultArray,$row);
}
echo json_encode($resultArray);

最新更新