remove quote on echo json_encode();
11,559
Solution 1
Try trim in php
<?php
$name = "Aman";
$str = json_encode($name);
echo trim($str, '"'); // output : Aman
?>
Solution 2
$help_name = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', $help_name);
Author by
Ree
Updated on June 05, 2022Comments
-
Ree almost 2 years
$result = mysql_query("SELECT * FROM $tableName WHERE id=1"); $array = mysql_fetch_array($result); $help_name = $array['name']; $req = $array['req']; //fetch result echo json_encode($help_name);
Problem is I'm getting the result with double quotes, how to remove the double quotes
-
Abdul Rafay about 7 yearsuse
htmlspecialchars($str, ENT_QUOTES)
PHP.net - Function htmlspecialchars -
jeroen about 7 yearsThat's the only way that your string will be valid json. If you don't want quotes, don't encode it to json.
-
Mani7TAM about 7 years
-
Masivuye Cokile about 7 yearsPossible duplicate of Remove double quote in json_encode()
-
ToolmakerSteve over 4 years@MasivuyeCokile - IMHO, this is not a duplicate. The linked question is more complex. It involves removing double-quotes from certain items within json_encoded data. This question is much simpler: it is simply the quotes around the whole string, when passing to
echo
.
-