2015-12-18 33 views
-1

我想從我的msg字符串去掉html標籤。用strip_tags去掉多個標籤()

我有以下字符串包含用戶輸入:

$msg="<a href="#">Hello world</a> ! <b>Welcome to venga club</b> .<br><li>We are here to entertain you....</li>"; 

我知道這是簡單的正則表達式與和的preg_replace剝離這些標籤,但我想如果可能做到這一點使用用strip_tags()。

我嘗試下面的代碼

echo strip_tags("<a><b><li><br>",$msg); 

但結果我得到的是黑色的,是有什麼問題的功能? 任何幫助都非常appriciated。

感謝

+4

對於神的緣故閱讀說明書。 –

回答

3

@u_mulder已通知 - 有時候這的確值得上做足閱讀手冊(晚上讀等):)一些額外的時間

function strip_tags ($str, $allowable_tags = null)

接受第一作爲輸入字符串的參數和作爲允許標籤的第二個參數。 對你的情況如何寫

http://php.net/manual/en/function.strip-tags.php

所以你應該把它例如像這樣:

$msg='<a href="#">Hello world</a> ! <b>Welcome to venga club</b> .<br><li>We are here to entertain you....</li>'; 

echo strip_tags($msg, '<a>');