隐藏论坛中的链接

时间:2015-06-04 23:52:10

标签: 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 = 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);

1 个答案:

答案 0 :(得分:0)

如果符合条件,我的建议是在页面上使用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
    }
?>

此php块将放置在您要显示的元素通常所在的容器元素内。请注意,如果语句的else部分为空,则可以将其删除。

这也适用于您想要应用于元素的特定id或类(如更改div的背景颜色),方法是插入id或类定义所在的块。

<div id="testdiv" <?php if(/*condition*/) {echo 'class="addedclass"';} ?> ><div>
相关问题