简体   繁体   English

PHP Regex-在html锚标记中查找url和文本

[英]PHP Regex - Find url and text in html anchor tags

Hi there I was wondering whether someone know how to remove both the url and the link text from all anchor tags in a big paragraph of text. 嗨,我想知道是否有人知道如何从大文本段落中的所有锚标记中同时删除URL和链接文本。 once remove if I could store them in an array for later use. 一旦删除,如果我可以将它们存储在数组中以备后用。

Im sure this is possible but I really struggle with regex. 我肯定这是可能的,但我真的很难与正则表达式。

Hopefully there is someone out there who has came across this before or who has some good knowledge on this. 希望那里有人曾经遇到过这个问题,或者对此有一些很好的了解。

Thank you 谢谢

Regex wasn't really designed to be a perfect html parser. 正则表达式并不是真正设计成完美的html解析器。 Have you tried doing a simpleXML load string? 您是否尝试过执行一个simpleXML加载字符串?

http://php.net/manual/en/function.simplexml-load-string.php http://php.net/manual/zh/function.simplexml-load-string.php

But for regex, check out these: 但是对于正则表达式,请查看以下内容:

What's the best way to remove <br> tags from the end of a string? 从字符串末尾删除<br>标记的最佳方法是什么?

How to convert multiple <br/> tag to a single <br/> tag in php 如何在php中将多个<br/>标记转换为单个<br/>标记

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM