Remove surrounding quotes json file, numbers only, php preg_replace

219 views Asked by At

Discover some solutions in C or other languages but at no use at php.

I need to replace all numbers in a (large) json file to avoid numbers will be seen as string when used in javascript.

for example:

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

What I want:

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

Have tried several things but I'm not a preg expert, something like this doesn't work:

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

How can I achieve my goal?

1

There are 1 answers

0
AudioBubble On BEST ANSWER
$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;