简体   繁体   中英

Display JSON_Encoded string variable, in HTML, without quotes

I have the variable $target in PHP and I am using json_encode in order to convert the PHP variable so that I can display it in HTML:

            $js_target = json_encode($target);




            $Content6 = <<<EOD
            
            <div>$js_target</div>
            
EOD;

            $Content6 .="\n";

            return $Content6;

This correctly results in the contents of variable $js_target being displayed on the webpage.

The issue is that the displayed data has quotes.

How can I ensure that quotes are not displayed when presenting the variable data on the webpage?

If your PHP variable is an array, you can convert it to a string and then remove the quotes with the following:

$js_target = str_replace('"', '', json_encode($target));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM