2011-08-31 102 views
0

当我使用这个函数来过滤一些字符时,我所有的链接都从html页面中删除。为什么我的链接消失了?

这是代码。

function AD($str) 
{ 
    # Quotes cleanup 
    $str = ereg_replace(chr(ord("`")), "'", $str);  # ` 
    $str = ereg_replace(chr(ord("´")), "'", $str);  # ´ 
    $str = ereg_replace(chr(ord("„")), ",", $str);  # „ 
    $str = ereg_replace(chr(ord("`")), "'", $str);  # ` 
    $str = ereg_replace(chr(ord("´")), "'", $str);  # ´ 
    $str = ereg_replace(chr(ord("“")), "\"", $str);  # “ 
    $str = ereg_replace(chr(ord("”")), "\"", $str);  # ” 
    $str = ereg_replace(chr(ord("´")), "'", $str);  # ´ 
    $str = ereg_replace(chr(ord("’")), "'", $str);  # ' 

$unwanted_array = array( 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 
          'Ê'=>'E', 'Ë'=>'Ë', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 
          'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 
          'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'ë', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 
          'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y'); 
$str = strtr($str, $unwanted_array); 

# Bullets, dashes, and trademarks 
$str = ereg_replace(chr(149), "•", $str); # bullet • 
$str = ereg_replace(chr(150), "–", $str); # en dash 
$str = ereg_replace(chr(151), "—", $str); # em dash 
$str = ereg_replace(chr(153), "™", $str); # trademark 
$str = ereg_replace(chr(169), "©", $str); # copyright mark 
$str = ereg_replace(chr(174), "®", $str);  # registration mark 

    return $str; 
} 

此外,我正在使用此其他代码来过滤内容。

$ mycontent = AD($ row ['post_content']);

$mycontent = substr($mycontent,0,450); 
$mycontent = preg_replace("/\[caption.*\[\/caption\]/", '', $mycontent); 
$mycontent = strip_tags($mycontent); 

为什么我的链接没有显示在帖子中?在我的cms中,他们显示在帖子中,但他们没有。

+0

通过链接你的意思'' ...标签? – JJJ

+3

一开始,'strip_tags'会去除你内容中的每一个html标签......阅读文档http://php.net/manual/en/function.strip-tags.php – Endophage

回答

1

strip_tags调用将删除所有HTML,包括链接。如果你想保持联系,然后通过表明您想保留<a>的第二个参数strip_tags

$mycontent = strip_tags($mycontent, '<a>');