我有我拉,看起来像这样的数组:将基本数组PHP数组
[157966745,275000353,43192565,305328212]
...
如何去采取这一“串”,并将其转换成PHP数组然后我可以操作。
我有我拉,看起来像这样的数组:将基本数组PHP数组
[157966745,275000353,43192565,305328212]
...
如何去采取这一“串”,并将其转换成PHP数组然后我可以操作。
这看起来像JSON,所以你可以使用json_decode
:
$str = "[157966745,275000353,43192565,305328212]";
$data = json_decode($str);
PHP explode就是为此而构建的。
$result = explode(',', $input)
方括号怎么样? – 2011-06-01 20:19:43
preg_replace('/([\[|\]])/','',$strarr);
$new_arr=explode(','$strarr);
有了确切的代码......
$string='[157966745,275000353,43192565,305328212]';
$newString=str_replace(array('[', ']'), '', $string); // remove the brackets
$createArray=explode(',', $newString); // explode the commas to create an array
print_r($createArray);
你的代码中有一些语法错误;) – 2011-06-01 20:20:51
现在已经修复。感谢您的注意。 – RRStoyanov 2011-06-01 20:40:33
$s = "[157966745,275000353,43192565,305328212]";
$matches;
preg_match_all("/\d+/", $s, $matches);
print_r($matches);
您有一个数组你想要的垂直...数组也? – ecchymose 2011-06-01 20:18:55
PHP不接受该格式作为数组,所以是的。 – switz 2011-06-01 20:21:21
这是从哪里来的?它真的是一个字符串吗?如果是这样,你应该重新命名你的问题。 – 2011-06-01 20:23:01