PHP 从 中提取链接标签
可能的重复:
PHP 字符串操作:提取 href
我正在使用 php,并且字符串内容为
我需要删除除“www.something.com”之外的所有内容 我认为这可以通过正则表达式来完成。 任何帮助表示赞赏! 谢谢
Possible Duplicate:
PHP String Manipulation: Extract hrefs
I am using php and have string with content =
<a href="www.something.com">Click here</a>
I need to get rid of everything except "www.something.com"
I assume this can be done with regular expressions.
Any help is appreciated!
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用 SimpleXML 可以很容易地做到这一点:
This is very easy to do using SimpleXML:
尝试一下:
结果:
www.something.com
更新:现在需要匹配引用样式,解决下面的评论。
Give this a whirl:
Result:
www.something.com
Updated: Now requires the quoting style to match, addressing the comment below.
我建议使用以下代码:
OUTPUT
这将处理 href 链接中的单引号
'
和双引号"
。I would suggest following code for this:
OUTPUT
This will take care of both single quote
'
and double quote"
in the href link.假设这总是变量的格式,下面应该可以解决问题。如果内容不是链接,则此操作将不起作用。本质上,它查找包含在两个引号内的数据。
Assuming that is ALWAYS the format of the variable, below should do the trick. If the content may not be a link, this won't work. Essentially it looks for data enclosed within two quotations.
也许您的问题并不那么简单,但这正是您所要求的:
$href
是:作为正则表达式,它可以这样表达:
这有帮助吗?
As probably you didn't meant your question that easy, but this does exactly what you're asking for:
$href
is:As a regular expression it can be expressed it as this is:
Is this helpful?