Reputation: 6610
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?
Upvotes: 1
Views: 218
Reputation:
$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;
Upvotes: 1