删除特殊字符,如lt;但不是锚定标签


Remove special characters like lt; but not anchor tag

如何删除特殊字符,如;lt;gt但不是锚定标记例如

&amp;lt;a href=&amp;quot;http://www.imdb.com/name/nm0005069/&amp;quot;&amp;gt;Spike Jonze&amp;lt;/a&amp;gt; This cause by <a class="primary-black" href="http://example.com/community/RobHallums">RobHallums</a> 

应该是

Spike Jonze This cause by <a class="primary-black" href="http://example.com/community/RobHallums">RobHallums</a>

这里有一个简单的例子:

<?php
// SET OUR DEFAULT STRING
$string = '&amp;lt;a href=&amp;quot;http://w...content-available-to-author-only...b.com/name/nm0005069/&amp;quot;&amp;gt;Spike Jonze&amp;lt;/a&amp;gt; This cause by <a class="primary-black" href="http://e...content-available-to-author-only...e.com/community/RobHallums">RobHallums</a>';
// USE PREG_REPLACE TO STRIP OUT THE STUFF WE DON'T WANT
$string = preg_replace('~&amp;lt;.*?&amp;gt;~', '', $string);
// PRINT OUT OUR NEW STRING
print $string;

我在这里所做的就是寻找&amp;lt;,然后是任何字符.,任何次数的*,直到它匹配字符串?的下一部分,即&amp;gt;

任何时候,只要它发现了这一点,它就会什么都不做。所以你只剩下你想要的文字了。

这是一个工作演示:

http://ideone.com/uSnY0b

使用html_entity_decode:

<?php $url = html_entity_decode('&amp;lt;a href=&amp;quot;http://www.imdb.com/name/nm0005069/&amp;quot;&amp;gt;Spike Jonze&amp;lt;/a&amp;gt;'); 
echo $url;
?>

输出将是:

<a href="http://www.imdb.com/name/nm0005069/">Spike Jonze</a>

编辑:

<?php 
  preg_match_all('/<a .*?>(.*?)<'/a>/',$url,$matches);
  //For Text Name
  echo $matches[1][0]; //output : Spike Jonze
?>