php - create assciative array while loop without quotes around values -
i have php code creates array display json:
$return_arr = array(); $sql="select * prices "; $rs=mysql_query($sql,$conn) or die(mysql_error()); while($result=mysql_fetch_array($rs)) { $return_arr[] = array('label' => $result["product"], 'id' => $result["sequence"]); }
currently, displays like:
var data = [{"label":"voip telephone numbers","id":"3"},{"label":"voip port submit","id":"4"}];
but need quotes (") removed label
, id
this regex use task:
$not_valid_json = preg_replace(array('%([{,])(\s*)"([a-z0-9]+)"\s*:%i','%\\\\/%','%"%'), array('$1$3:','/','\''), json_encode($value));
be aware though not valid json anymore according spec, still evaluate in javascript.
also note doesn't work great if value being encoded contains quotes.
Comments
Post a Comment