【发布时间】:2015-04-22 00:39:00
【问题描述】:
如何根据图像 src 提取给定 HTML 的锚点 href?
例子:
<a href="http://idontneedthis.com"><img src="path/to/image/1.gif" /></a>
<a href="http://iwantthis.com"><img src="path/to/image/2.gif" /></a>
<a href="http://idontneedthisagain.com"><img src="path/to/image/3.gif" /></a>
在这种情况下,我需要使用2.gif 的 src 获取链接图像的链接。那将是具有 href http://iwantthis.com
【问题讨论】:
-
不,如果我知道 img src 的值,我想要 href 的值。
-
查看第二个答案,即使用
DOMDocument的答案。那应该做你想做的事
标签: php regex parsing xpath extract