Reputation: 23
I need to extract name from a big data pouch .
$frame = '\"Amy Dardomba\":1,\"Kisb Muj Lorence\":1,\"Apkio Ronald\":1,....
there are more than 200-300 names which i have to put in array .
i tried ,
preg_match_all('#\/"(.*)\/":1#',$frame,$imn);
print_r($imn);
but it doesnt works . Please help me .
Thanks
Upvotes: 0
Views: 61
Reputation: 2992
\/
will match /
character but you need to match \
so use \\
instead :
preg_match_all('#\\"(.*?)\\":1#',$frame,$imn);
Also added a ?
for non-greedy regex.
Upvotes: 0
Reputation: 88697
That data looks like some bastardised JSON to me. Assuming the format of your code is the same all the way as above, try this:
// 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
...
)
*/
Upvotes: 1
Reputation: 3464
$input = '\"Amy Dardomba\":1,\"Kisb Muj Lorence\":1,\"Apkio Ronald\":1';
preg_match_all('#"([a-zA-Z\x20]+)"#', stripslashes($input), $m);
look in $m[1]
Upvotes: 0