【发布时间】:2015-02-23 16:27:29
【问题描述】:
我想在一个 html 页面中找到一个特定的 url 并获得它的一部分。 网址在此页面中:
http://site1.com/games/arcade/139173-angry-birds-friends-1-7-0.html`
就像
http://download.site2.org/?server=2&apkid=com.rovio.angrybirdsfriends&ver=1.7.0
我想要它的 3 个部分:
- 2
- com.rovio.angrybirdsfriends
- 1.7.0
我的代码:
$html = file_get_contents("http://site1.com/games/name/139173-angry-birds-friends-1-7-0.html");
preg_match("/download(.*)/", $html, $results)
echo = $results[0];
【问题讨论】:
-
错误 #1:使用正则表达式解析 html。使用 dom 解析器。
-
第一个例子中的
2应该从什么开始解析? -
网址在 $html = file_get_contents("site1.com/games/name/…);
标签: php regex preg-match file-get-contents