I have cities in my mysql table. I am getting those through an mysql query. Then I want to display in json format. However, json doesn't display due to not valid characters in the city names. Can anyone help on this? here is my code. I want to get json format somehow by using strip_tags or anything with this array. please help on this guys.
$zone = $mcon->query("SELECT name from tbl_cities ORDER BY name ASC");
$data = array();
while ($value = $zone->fetch_assoc()) {
$data[] = $value;
}
echo json_encode(array("text" => $data));
SELECT Replace(
name
, '-', ' ' ) from tbl_cities ORDER BY name ASCThis will replace all occurances of hyphens with spaces. There are many functions built into SQL to format the data before you pass it json.
I hope this helps.