为什么我的链接消失了


Why my links are disappeared?

当我使用这个函数来过滤一些字符时,我的所有链接都从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中,它们是显示的,但在帖子中它们不是。

strip_tags调用正在删除所有HTML,包括链接。如果您想保留链接,那么将第二个参数传递给strip_tags,表明您想保留<a>:

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