从PHP字符串中提取特定值

时间:2013-04-26 23:47:11

标签: php string twitter extract

我正在尝试学习动态分页的高音扬声器结果的max_id。

搜索元数据如下:

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字符串中的任何其他数字?

谢谢!

2 个答案:

答案 0 :(得分: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 :(得分:2)

正则表达式?

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

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