2
 $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

Ikhlak S.
  • 8,578
  • 10
  • 57
  • 77
Ree
  • 53
  • 2
  • 3
  • 9
  • 1
    use `htmlspecialchars($str, ENT_QUOTES)` [PHP.net - Function htmlspecialchars](http://php.net/manual/en/function.htmlspecialchars.php) – Abdul Rafay Feb 28 '17 at 12:49
  • 1
    That's the only way that your string will be valid json. If you don't want quotes, don't encode it to json. – jeroen Feb 28 '17 at 12:53
  • Please refer [http://stackoverflow.com/questions/13938645/remove-double-quote-in-json-encode] [http://stackoverflow.com/questions/8837659/remove-double-quotes-from-a-json-encoded-string-on-the-keys] – Mani7TAM Feb 28 '17 at 12:54
  • Possible duplicate of [Remove double quote in json\_encode()](http://stackoverflow.com/questions/13938645/remove-double-quote-in-json-encode) – Masivuye Cokile Feb 28 '17 at 12:59
  • @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`. – ToolmakerSteve Oct 06 '19 at 14:30

2 Answers2

10

Try trim in php

<?php 
$name = "Aman";
$str = json_encode($name);
echo trim($str, '"');  // output : Aman
?>
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40
1
$help_name = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', $help_name);
Mani7TAM
  • 469
  • 3
  • 10