2013-04-26 100 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];