2012-03-28 2 views
0

큰 데이터 주머니에서 이름을 추출해야합니다.지정된 문자의 패턴

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

배열에 넣어야하는 200-300 개 이상의 이름이 있습니다.

내가 시도는

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

하지만 작품을 나던. 도와주세요.

감사

답변

1

그 데이터는 저에게 JSN을 저지른 것처럼 보입니다. 같은 모든 방법 위와 같이 코드의 형식을한다 가정하면,이 시도 :

// 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]

에서