i cant seem to fix this little gremlin.
I have a mySQL database which table has a description field.
My client has used the ' character quite a lot and this is breaking the json i am generating from php.
My script is as follows:
... database call...
$totalRows_rs_results = mysql_num_rows($rs_results);
if($totalRows_rs_results >0){
$myData = array();
//echo('locations near this unitbase:');
$myData['id'] = $row_rs_results['id_loc'];
$myData['slug'] = $row_rs_results['slug_loc'];
$myData['name'] = $row_rs_results['name_loc'];
$myData['showname'] = $row_rs_results['showname_loc'];
$myData['description'] = utf8_encode($row_rs_results['description_loc']);
$myData['image'] = getDefaultLocationImage($database_reelfilm, $reelfilm, $row_rs_results['id_loc']);
$myAddress = ($row_rs_results['address_loc'].' '.$row_rs_results['postcode_loc']);
$myData['address'] = $myAddress;
$myData['maplat'] = $row_rs_results['maplat_loc'];
$myData['maplong'] = $row_rs_results['maplong_loc'];
$myData['parking'] = $row_rs_results['parkinginfo_loc'];
$myData['features'] = $row_rs_results['internalfeatures_loc'] . ' ' . $row_rs_results['externalfeatures_loc'];
//$myData['categorys'] = getCategorys($database_reelfilm, $reelfilm, $row_rs_results['id_loc']);
$json[] = $myData;
$myJSON = json_encode($json);
return $myJSON;
};
<span class='showOnMap' data-location='<?php echo makeJSON($database_reelfilm, $reelfilm, 'location', $row_rs_locations['id_loc']);?>' '>
<img src="/images/Icons/map-icon.png" width="32" height="32">
</span>
the outputted json is fine until i come to a record with the aforementioned ' character.
if i remove the offending ' character from the record i get correct output:
<span class="showOnMap" data-related="" data-categorys="" data-location="[{"id":"29","slug":"the-butts","name":"The Butts","showname":"1","description":"Controllable period street location. Looks like an A road or a bus route. Surrounding houses are Georgian or early Victorian.","image":"The Butts 3.jpg","address":"Brentford\r\nLondon TW8 8BQ","maplat":"51.4847373","maplong":"-0.30824250000000575","parking":"","features":" "}]">
<img width="32" height="32" src="/images/Icons/map-icon.png">
</span>
data out generated with the ' character:
<span class="showOnMap" data-related="" data-categorys="" "}]'="" 8bq","maplat":"51.4847373","maplong":"-0.30824250000000575","parking":"","features":"="" tw8="" 3.jpg","address":"brentford\r\nlondon="" butts="" victorian.","image":"the="" early="" georgian="" are="" houses="" surrounding="" route.="" bus="" a="" or="" road="" a'="" data-location="[{"id":"29","slug":"the-butts","name":"The Butts","showname":"1","description":"Controllable period street location. Looks like an ">
<img width="32" height="32" src="/images/Icons/map-icon.png">
</span>
Now it seems very unprofessional to me to tell my client to go through and remove all the offending ' characters (theres over 1000 records).
Ive tried htmlspecialchars() , utf8_encode() to try and fix the problem, not sure which one i need to be using, could anyone point me in the right direction please?