2015-06-04 160 views
2

我试图隐藏从注册会员没有,BB代码的作品链接,并将其隐藏,但是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); 
+0

没有任何一个正则表达式模式看起来像他们甚至试图匹配HTML锚点标记,但我不建议您尝试。可能值得你看看[DOMDocument](http://php.net/DomDocument)和XPath。 –

回答

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部分是空的,你可以离开它。

这也能为你想申请到一个元素(如改变一个div的背景色),通过插入其中ID或类定义是块特定的ID或类工作。

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