2015-06-04 156 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>