I want to remove all double quotes from a JSON file using PHP.
我想使用PHP从JSON文件中删除所有双引号。
The following code outputs all the variables to a JSON file named example.json
:
以下代码将所有变量输出到名为example.json的JSON文件:
$var_geoJSON = 'var geoJSON = ';
file_put_contents('jsonfun.json', $var_geoJSON);
file_put_contents('jsonfun.json', json_encode($geojson, JSON_NUMERIC_CHECK), FILE_APPEND);
I was trying to get it to output something like this:
我试图让它输出这样的东西:
var geoJSON = {...}
var geoJSON = {...}
Yet it outputs something like this:
然而它输出的内容如下:
"var geoJSON = " {...}
“var geoJSON =”{...}
I am currently working with geoJSON to output to the open source leaflet.js mapping library, and the syntax requires that I have var geoJson = {...}
instead of having "var geoJSON = "{...}
.
我目前正在使用geoJSON输出到开源的leaflet.js映射库,语法要求我有var geoJson = {...}而不是“var geoJSON =”{...}。
I have tried using the PHP
command preg_replace()
replacing all the ""
with spaces, yet that still didn't work and it outputted the same thing with the double quotes.
我已经尝试使用PHP命令preg_replace()用空格替换所有“”,但仍然无效,它输出与双引号相同的东西。
Any ideas?
有任何想法吗?
1 个解决方案
#1
0
Just use str_replace
function http://www.w3schools.com/php/func_string_str_replace.asp example: $result = str_replace('"', '', $json)
只需使用str_replace函数http://www.w3schools.com/php/func_string_str_replace.asp示例:$ result = str_replace('“','',$ json)
#1
0
Just use str_replace
function http://www.w3schools.com/php/func_string_str_replace.asp example: $result = str_replace('"', '', $json)
只需使用str_replace函数http://www.w3schools.com/php/func_string_str_replace.asp示例:$ result = str_replace('“','',$ json)