首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从PHP字符串中提取特定值

从PHP字符串中提取特定值
EN

Stack Overflow用户
提问于 2013-04-27 07:47:11
回答 2查看 97关注 0票数 1

我正在尝试学习动态分页的推特结果的max_id。

搜索元数据如下:

代码语言:javascript
运行
复制
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值。

因此,有没有一种方法可以从?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1字符串中提取数字326811400389406719 (以及其他类似的数字?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-27 08:04:48

代码语言:javascript
运行
复制
$str = "?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1"    
parse_str($str, $output);
$max_id = $output['?max_id'];
//print_r($output);
票数 3
EN

Stack Overflow用户

发布于 2013-04-27 07:50:49

正则表达式?

代码语言:javascript
运行
复制
$string = '?max_id=326811400389406719&q=%23helloworld&count=10&include_entities=1';

preg_match('/max_id=(\d+)/', $string, $matches);
$max_id = $matches[1];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16246776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档