提取所有 url Href php
我有一个包含许多链接的 HTML。我目前能够获得链接,只是全部结束,我只会获得某个单词。
$dom = new DOMDocument;
$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
foreach ($links as $link){
echo $link->getAttribute('href');
}
我只会列出包含某个单词的链接, 示例:sendspace.com
结果或多或少低于:
http://www.fileserve.com/file/eDpDMm9sad/
http://www.fileserve.com/file/7s83hjh347/
然后我会转换这些链接到 sha1。
转换后保存 html sha1 已应用于包含单词的链接。
I have an HTML with many links. I am currently able to get links, just all over, I would only get a certain word.
$dom = new DOMDocument;
$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
foreach ($links as $link){
echo $link->getAttribute('href');
}
I would list only links that contained a certain word,
example: sendspace.com
result would be more or less below the:
http://www.fileserve.com/file/eDpDMm9sad/
http://www.fileserve.com/file/7s83hjh347/
I would then convert these links to sha1.
after conversion to save the html sha1 already applied to the links with the words contained.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用正则表达式来匹配字符串中的单词(或其他任何内容),如下所示:
You can use regex to match your word (or whatever else) in the string like so:
使用 phpQuery,您可以遍历 DOM 并找到锚点 (
),其中
href
属性包含您想要的内容:Using phpQuery, you can traverse the DOM and find the anchors (
<a>
) with thehref
attribute containing what you want: