Php 隐藏论坛中的链接

Php 隐藏论坛中的链接,php,Php,我试图对未注册的成员隐藏链接,BBcode可以工作并且可以隐藏,但HTML代码不起作用 比如说, [link=http://www.brandbucket.com/]Brand Bucket[/link] 这隐藏得很好 另一方面 <a href="http://www.char5.com/" target="_blank">http://www.char5.com</a> 这根本不隐藏,超链接工作正常 这是下面的代码,如需任何帮助,请提供,谢谢 $text

我试图对未注册的成员隐藏链接,BBcode可以工作并且可以隐藏,但HTML代码不起作用

比如说,

[link=http://www.brandbucket.com/]Brand Bucket[/link]
这隐藏得很好

另一方面

<a href="http://www.char5.com/" target="_blank">http://www.char5.com</a>

这根本不隐藏,超链接工作正常

这是下面的代码,如需任何帮助,请提供,谢谢

    $text = preg_replace("/\[file\=(.*?)\](.*?)\[\/file\]/is", $rep, $text);
$text = preg_replace("/\[link\=(.*?)\](.*?)\[\/link\]/is", $rep, $text);
$text = preg_replace("/\[url\=(.*?)\](.*?)\[\/url\]/is", $rep, $text);
$text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<,]*)#is", "\\1".$rep, $text);
$text = preg_replace("#(^|[\n \]])((www|ftp)\.[\w+-]+?\.[\w+\-.]*(?(?=/)(/.+?(?=\s|,\s))|(?=\W)))#is", "\\1".$rep, $text);
$text=preg\u replace(“/\[file\=(.*?\])(.*?\[\/file\]/is”,$rep,$text);
$text=preg\u replace(“/\[link\=(.*?\])(.*?\[\/link\]/is“,$rep,$text);
$text=preg\u replace(“/\[url\=(.*?\])(.*?\[\/url\]/is”,$rep,$text);

$text=preg_replace(“#(^ |[\n])([\w]+?:/[^\”\n\r\t我的建议是使用
if-else
语句,如果满足条件,则将
echo
元素添加到页面上

例如,在我的网站上,我有一个注销按钮。它只显示用户是否登录

<?php
    if(/*user is logged in*/) {
        echo 'This is where the element code is placed';
    }
    else {
        //user is not logged in so don't echo the element
    }
?>

虽然我不建议您尝试,但您的正则表达式模式中没有一个看起来像是试图匹配HTML锚定标记。可能值得您查看和XPath。
<div id="testdiv" <?php if(/*condition*/) {echo 'class="addedclass"';} ?> ><div>