可耻的伸个手, 关于正则

2015-04-24 05:42:23 +08:00
 supman

<span class="a"><div class="userID" title="189">189</div></span>
<span class="b"><div class="userID" title="190">190</div></span>
<div class="userGroup" title="2">2</div>

麻烦大家帮忙想想法子, 能不能只提取 第一行的数字 189, 不论是title 还是标签对内的, 只要能提取到就好。

1694 次点击
所在节点    问与答
5 条回复
xiaogui
2015-04-24 06:15:34 +08:00
先用 class=“a” 提取,不久好提取了吗?
laoyuan
2015-04-24 08:11:35 +08:00
preg_match("/<span class=\"a\">.+?title=\"(\d+)/", $str, $match);
laoyuan
2015-04-24 08:12:28 +08:00
结果
Array
(
[0] => <span class="a"><div class="userID" title="189
[1] => 189
)
kasp
2015-04-24 08:34:13 +08:00
phpquery可以轻松搞定
supman
2015-04-24 08:38:45 +08:00
@laoyuan

感谢 :)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/185876

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX