2013-04-26 96 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" 
} 

這將是非常方便的,以我的腳本旁邊結果轉換max_id到PHP的值。

有沒有因此一個方法來提取數326811400389406719(以及任何其他數字,如從?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1字符串?

謝謝!

+1

[parse_str ](http://www.php.net/manual/en/function.parse-str.php)可能會幫助你 – 2013-04-26 23:55:02

回答

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 &計數= 10&include_entities = 1" ,1); //放下第一個「?」 – 2013-04-27 00:06:53

2

正則表達式?

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

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