2016-12-21 193 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

相關問題