2016-12-21 31 views
0

发现一些C或其他语言的解决方案,但在PHP没有用。去除周围的引号json文件,仅数字,php preg_replace

我需要替换(大)json文件中的所有数字,以避免在JavaScript中使用数字时将被视为字符串。

例如:

[["Alt","128","36.00","36.00","test" .....]] 

我想要什么:

[["Alt",128,36.00,36.00,"test" .....]] 

试过几件事情,但我不是预浸专家,这样的事情不工作:

$sOutput = preg_replace('/^(\'[0-9]\'|"([0-9])")$/', '$2$3', $sOutput); 
die($sOutput); 

我该如何实现我的目标?

回答

1
$re = '/\"([0-9.]+)\"/m'; 
$str = '[["Alt","128.12","36.00","36.00","test" ....., "123.45"]]'; 
$subst = '$1'; 

$result = preg_replace($re, $subst, $str); 

echo "The result of the substitution is ".$result; 
+0

Your briljant!非常感谢! – Codebeat