'제거'에 해당되는 글 2건

  1. 2008/07/15 html 태그 제거 하기
  2. 2008/02/26 결국 구글애드센스를 버렸다...

html 태그 제거 하기

Web(웹) Study/PHP 2008/07/15 20:51 by 하늘이야기
 

<?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   ?>


크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/07/15 20:51 2008/07/15 20:51

댓글을 달아 주세요

[로그인][오픈아이디란?]

1 

달력

«   2010/03   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

카테고리

전체 (577)
My Story (47)
My Project List (8)
세상을 바라보다. (158)
Web(웹)표준 신기술 (37)
Web(웹) Study (154)
데이터베이스 Study (10)
공부 해 Boa요. (31)
IT트랜드 & 정보 (64)
문. 화. 생. 활. (14)
DSLR과 함께하기 (9)
스크랩 정보들 (10)
이야기 광장 (18)
레크레이션 (17)

archive