任何人都知道解析用戶提交的評論的任何示例php(理想codeigniter)代碼。去除褻瀆和HTML標籤等?評論解析器的示例代碼
3
A
回答
1
嘗試strip_tags擺脫提交的任何html。如果您只想確保註釋中不顯示任何html,則可以使用htmlspecialchars來轉義標記 - 按照Matchu的示例,使用它時會發生的意外影響要少於strip_tags。
對於一個字過濾器,取決於你想要去的深度,網上有很多例子,從simple到complex。下面是傑克Olefsky的例子代碼(簡單的一個以前鏈接):
<?
//This is totally free to use by anyone for any purpose.
// BadWordFilter
// This function does all the work. If $replace is 1 it will replace all bad words
// with the wildcard replacements. If $replace is 0 it will not replace anything.
// In either case, it will return 1 if it found bad words or 0 otherwise.
// Be sure to fill the $bads array with the bad words you want filtered.
function BadWordFilter(&$text, $replace)
{
//fill this array with the bad words you want to filter and their replacements
$bads = array (
array("butt","b***"),
array("poop","p***"),
array("crap","c***")
);
if($replace==1) { //we are replacing
$remember = $text;
for($i=0;$i<sizeof($bads);$i++) { //go through each bad word
$text = eregi_replace($bads[$i][0],$bads[$i][5],$text); //replace it
}
if($remember!=$text) return 1; //if there are any changes, return 1
} else { //we are just checking
for($i=0;$i<sizeof($bads);$i++) { //go through each bad word
if(eregi($bads[$i][0],$text)) return 1; //if we find any, return 1
}
}
}
//this will replace all bad words with their replacements. $any is 1 if it found any
$any = BadWordFilter($wordsToFilter,1);
//this will not repace any bad words. $any is 1 if it found any
$any = BadWordFilter($wordsToFilter,0);
?>
許多更多的例子可以found easily在網絡上。
相關問題
- 1. 評論代碼或不評論代碼
- 2. 用於Java源代碼的靜態代碼解析器提取方法/評論
- 3. 服務器插座問題(示例代碼評論)
- 4. 如何解析並顯示評論
- 5. 已移至代碼評論評論
- 6. JS代碼:評論
- 7. Jquery代碼評論
- 8. PHP評論代碼
- 9. PHP:評論代碼
- 10. 解析JIRA webhook評論
- 11. 評論我的代碼
- 12. 評論我的Scala代碼
- 13. WordPress的 - 評論html代碼
- 14. netbeans中的評論代碼?
- 15. ODP.NET代碼示例評論或最佳實踐
- 16. 最新Ruamel評論示例
- 17. 代碼評論寶石
- 18. 代碼評論與CI
- 19. Python Regex中評論代碼
- 20. 如何評論PHP代碼
- 21. Turtle Gradient Color(評論代碼)
- 22. 安全代碼評論
- 23. 評論C++代碼,visual studio
- 24. 評論此C++代碼
- 25. 窯評審委員會沒有顯示我的代碼評論?
- 26. 解析Facebook的評論圖形API
- 27. 重新解析Facebook的HTML5評論框
- 28. 解析BASH腳本中的heredoc評論
- 29. 瞭解蘋果示例代碼中的xml解析
- 30. 使用phtml代碼而不是xml代碼來顯示評論
當然,CodeIgniter有一個用於轉義HTML的簡單組件,對吧?字詞過濾器應該足夠小。 – Matchu 2010-02-02 00:20:37