2013-04-26 12 views
0

동적 페이지 매김에 대한 트위터 결과의 max_id를 배우려고합니다. 그것은 내 스크립트에 매우 편리 할 것 PHP 문자열에서 특정 값 추출

search_metadata: { 
    completed_in: 0.033, 
    max_id: 326811859678277600, 
    max_id_str: "326811859678277634", 
    next_results: "?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1", 
    query: "%23helloworld", 
    refresh_url: "?since_id=326811859678277634&q=%23helloworld&include_entities=1", 
    count: 10, 
    since_id: 0, 
    since_id_str: "0" 
} 

는 PHP 값 옆 결과에 max_id 변환 :

검색 메타 데이터는 다음과 같습니다.

숫자 326811400389406719 (그리고 ?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1 문자열에서 그?

감사합니다!

+1

[parse_str ] (http://www.php.net/manual/en/function.parse-str.php) 도움이 될 수도 있습니다 –

답변

3
$str = "?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1"  
parse_str($str, $output); 
$max_id = $output['?max_id']; 
//print_r($output); 
+1

$ str = substr ("? max_id = 326811400389406719 & q = % 23helloworld & count = 10 & include_entities = 1 ", 1); // 첫 번째 "?" –

2

정규 표현식과 같은 다른 번호를 추출하는 것이 방법이 있나요?

$string = '?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1'; 

preg_match('/max_id=(\d+)/', $string, $matches); 
$max_id = $matches[1];