사용자가 제출 한 주석을 구문 분석하기위한 샘플 php (이상 코드 서명자) 코드를 알고 있습니다. 욕설과 HTML 태그 등을 제거 하시겠습니까?주석 파서의 예제 코드
3
A
답변
1
제출 된 HTML을 제거하려면 strip_tags을 시도하십시오. 댓글에 html이 표시되지 않도록하려면 htmlspecialchars을 사용하면됩니다. Matchu의 예에 따르면 strip_tags보다 의도하지 않은 영향이 적습니다.
단어 필터의 경우, 원하는 단어의 깊이에 따라 simple에서 complex까지 많은 예제가 웹에 있습니다. 이것의
<?
//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 수 있습니다 : 여기 제이크 Olefsky의 예에서 코드 (이전에 링크 간단한 하나)입니다.
관련 문제
- 1. 코드 예제
- 2. 코드 문서의 "예제 사용"표시
- 3. 파서의 오류
- 4. 소스 코드 주석 도구
- 5. 코드를 주석 처리하여 코드를 테스트하는 예제
- 6. JavaDoc의 주석이있는 코드 예제
- 7. 자바 스크립트 예제 코드
- 8. Android SSH 예제 코드
- 9. NUnit 예제 코드?
- 10. Python 클로저 예제 코드
- 11. EDMessage 예제 코드?
- 12. 프로그래밍 언어의 코드 예제
- 13. 예제 코드 행 이해하기
- 14. SWT 코드 예제 다음
- 15. Doxygen의 코드 예제
- 16. 수학 파서의 스마트 디자인?
- 17. NSXML 파서의 누설
- 18. ASP 닷넷 프로젝트의 코드 주석
- 19. Maven을 사용한 예제 코드 아카이브
- 20. 벼룩이나 hierholzer 알고리즘의 코드 예제?
- 21. 루피 믿음 전파 코드 예제
- 22. iPhone 용 코드 예제 UIGetScreenImage
- 23. 펄 순 :: OAuth2를 예제 코드
- 24. 코드 생성의 간단한 JDT 예제
- 25. 도서 및 쉘 코드 예제
- 26. 코드 예제 작업을 얻는 방법
- 27. python 서버 래퍼 예제 코드
- 28. 인위적인 예제 코드 찾기 : continuations!
- 29. Facebook을 ColdFusion과 연결하는 예제 코드
- 30. 컴파일러와 파서의 차이점은 무엇입니까?
확실히 CodeIgniter에는 HTML을 이스케이프하기위한 쉬운 구성 요소가 있습니다. 맞습니까? 단어 필터는 아주 사소해야합니다. – Matchu