I'm processing a request through ajax and return a json encoded result.
$sql = "SELECT * from products WHERE product_name='".$choosen."'";
$result = mysql_query($sql) or die("Error");
$row = mysql_fetch_assoc($result);
echo json_encode($row);
I parse this json in my javascript as follows,
success:function(result)
{ var Data = JSON.parse(result); }
Every data is returned and ended up successfully except columns contain ± symbol (column_1 and column_2). I found it by remove this(±) symbol manually from database, then it works fine.
So I've decided to replace ' ± ' with ' + or - ' in every instance. I rewrite the code as follows,
$sql="SELECT * from products WHERE product_name='".$choosen."'";
$result = mysql_query($sql) or die("Error");
$row = mysql_fetch_assoc($result);
$row["column_1"] = str_replace('±','+ or -',$row["column_1"]);
$row["column_2"] = str_replace('±','+ or -',$row["column_2"]);
echo json_encode($row);
Now the problem is, **str_replace() isn't working for this character ±.
I have two option to kill this bug. Either replacing '±' this symbol or find a way to encode ± this symbol, to json without any replacement. But I don't know how to find either ways. Please help me out.