<?php
// $document should contain an HTML document.
// This will remove HTML tags, javascript-x sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array ('@<script-x[^>]*?>.*?</script-x>@si', // Strip out javascript-x
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@([\r\n])[\s]+@', // Strip out white space
'@&(quot|#34);@i', // Replace HTML entities
'@&(amp|#38);@i',
'@&(lt|#60);@i',
'@&(gt|#62);@i',
'@&(nbsp|#160);@i',
'@&(iexcl|#161);@i',
'@&(cent|#162);@i',
'@&(pound|#163);@i',
'@&(copy|#169);@i',
'@&#(\d+);@e'); // evaluate as php
$replace = array ('',
'',
'\1',
'"',
'&',
'<',
'>',
' ',
chr(161),
chr(162),
chr(163),
chr(169),
'chr(\1)');
$text = preg_replace($search, $replace, $document);
strip_tags(get_the_content($document));
?>
1 <?php
2 // $document should contain an HTML document.
3 // This will remove HTML tags, javascript-x sections
4 // and white space. It will also convert some
5 // common HTML entities to their text equivalent.
6 $search = array ("'<script-x[^>]*?>.*?</script-x>'si", // Strip out javascript-x
7 "'<[/!]*?[^<>]*?>'si", // Strip out HTML tags
8 "'([rn])[s]+'", // Strip out white space
9 "'&(quot|#34);'i", // Replace HTML entities
10 "'&(amp|#38);'i",
11 "'&(lt|#60);'i",
12 "'&(gt|#62);'i",
13 "'&(nbsp|#160);'i",
14 "'&(iexcl|#161);'i",
15 "'&(cent|#162);'i",
16 "'&(pound|#163);'i",
17 "'&(copy|#169);'i",
18 "'&#(d+);'e"); // evaluate as php
19 $replace = array ("",
20 "",
21 "\1",
22 """,
23 "&",
24 "<",
25 ">",
26 " ",
27 chr(161),
28 chr(162),
29 chr(163),
30 chr(169),
31 "chr(xxx1)"); // remove the "xxx" - this is just for showing the source
32 $text = preg_replace($search, $replace, $document);
33 ?>
"PHP" 카테고리의 다른 글
[2009/10/06] 빠른 PHP 속도를 유지 하기 위한 것. [2008/07/15] html 태그 제거 하기 [2008/09/02] PHP 코드를 최적화하는 40가지 팁 (번역) [2008/07/15] 한자를 한글로 변환하는 함수! [2011/01/10] PHP 문자열 처리 함수 [2009/10/06] PHP 언어 문법 함수 정리 [2010/11/24] 날짜의 요일 구하기 [2009/11/18] PHP에서 "HTTP / HTTPS" Request하기 [2009/10/06] PHP - GD로 이미지 합치기 텟트 출력 [2008/01/18] IP 주소 정수로 변환하기





