2012-03-28 9 views
0

大きなデータポーチから名前を抽出する必要があります。指定された文字のパターン

$frame = '\"Amy Dardomba\":1,\"Kisb Muj Lorence\":1,\"Apkio Ronald\":1,.... 

私は、アレイに配置する必要があります以上の200から300名があります。

私は

preg_match_all('#\/"(.*)\/":1#',$frame,$imn); 
print_r($imn); 
を試してみましたが、それは作品をdoesntの。私を助けてください 。

答えて

1

そのデータは、私に荒廃した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 
     ... 
) 
*/ 

See it working

0

\/

おかげで/文字に一致しますが、あなたは\\代わりに使うので\と一致する必要があります。

preg_match_all('#\\"(.*?)\\":1#',$frame,$imn); 

はまた、非貪欲正規表現のための?を追加しました。

0
$input = '\"Amy Dardomba\":1,\"Kisb Muj Lorence\":1,\"Apkio Ronald\":1'; 
preg_match_all('#"([a-zA-Z\x20]+)"#', stripslashes($input), $m); 

$m[1]

関連する問題