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);
Share:
11,559
Ree
Author by

Ree

Updated on June 05, 2022

Comments

  • Ree
    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