简体   繁体   English

strip_tags不能正常工作的ahref

[英]strip_tags not working properly of ahref

I am using strip_tags() function to extract the contents of a link (the text part not the link part). 我正在使用strip_tags()函数提取链接的内容(文本部分而不是链接部分)。 The string is obtained from twitter. 该字符串是从twitter获得的。 Unfortunately it returns the same thing. 不幸的是,它返回相同的东西。

The code is as follows 代码如下

$a = $cur['source'];
echo strip_tags($a);

Input 输入项

<a href="http://twitter.com/download/android">Twitter for Android</a>

Output 输出量

<a href="http://twitter.com/download/android">Twitter for Android</a>

When I copy pasted the input to a string and tried strip_tags its working perfectly. 当我将输入复制粘贴到字符串并尝试strip_tags时,它可以正常工作。 What could be the reason/? 可能是什么原因/?

You needed to use html_entity_decode because your HTML looked to be HTML, but wasn't (in fact, all html codes were themselves encoded to other html codes). 您需要使用html_entity_decode,因为您的HTML看上去是HTML,但实际上不是(实际上,所有html代码本身都已编码为其他html代码)。

If you try to echo htmlentities($cur['source']) , you'll see 如果您尝试echo htmlentities($cur['source']) ,则会看到

&lt;a href=&quot;http://twitter.com/download/android&quot;&gt;Twitter for Android&lt;/a&gt;

This mean this string can be displayed on a browser without being interpreted as html (as a link in your case). 这意味着该字符串可以在浏览器上显示,而无需解释为html(在您的情况下为链接)。 That's very useful if for example, I want to display <html> on Stackoverflow without seeing my <html> tag interpreted. 例如,如果我想在Stackoverflow上显示<html>而不看到我的<html>标记被解释,这将非常有用。

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

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