我需要从大数据包中提取名称。指定字符的模式
$frame = '\"Amy Dardomba\":1,\"Kisb Muj Lorence\":1,\"Apkio Ronald\":1,....
有超过200-300名我必须放在数组中。
我想,
preg_match_all('#\/"(.*)\/":1#',$frame,$imn);
print_r($imn);
但它不工作。请帮帮我 。
感谢
我需要从大数据包中提取名称。指定字符的模式
$frame = '\"Amy Dardomba\":1,\"Kisb Muj Lorence\":1,\"Apkio Ronald\":1,....
有超过200-300名我必须放在数组中。
我想,
preg_match_all('#\/"(.*)\/":1#',$frame,$imn);
print_r($imn);
但它不工作。请帮帮我 。
感谢
该数据看起来像一些混蛋的JSON给我。假设你的代码的格式是一样的一路如上,试试这个:
// Two pass approach to interpollate escape sequences correctly
$toJSON = '{"json":"{'.$frame.'}"}';
$firstPass = json_decode($toJSON, TRUE);
$secondPass = json_decode($firstPass['json'], TRUE);
// Just get the keys of the resulting array
$names = array_keys($secondPass);
print_r($names);
/*
Array
(
[0] => Amy Dardomba
[1] => Kisb Muj Lorence
[2] => Apkio Ronald
...
)
*/
\/
将匹配/
字符,但你需要匹配\
所以使用\\
代替:
preg_match_all('#\\"(.*?)\\":1#',$frame,$imn);
同时加入了一个?
非贪婪的正则表达式。
$input = '\"Amy Dardomba\":1,\"Kisb Muj Lorence\":1,\"Apkio Ronald\":1';
preg_match_all('#"([a-zA-Z\x20]+)"#', stripslashes($input), $m);
看在$m[1]