PHP를 이용하여 HTML태그를 제거하려고 하려고 합니다.
글쓴이: 지수아비 / 작성시간: 수, 2010/06/16 - 2:12오후
php를 이용하여 웹페이지 소스에서 태그를 제거하려고하는데요...
단순하게 strip_tags() 함수를 사용해서는 원하는 결과를 얻을수가 없더군요.
예를들어 $A 라는 변수에 아래와 같은 html 소스가 들어있을경우 strip_tags 함수를 이용하여
출력을 하면...
<? $A = " <html> <title>타이틀입니다</title> <script> function test() { alert('1'); } </script> <script type='text/javascript' src='test.js'></script> <link rel='stylesheet' href='Style.css' type='text/css'> <style> #aaa{width:10px;} #aaa b{border-bottom:1px solid #fff; padding:5px 0 3px 12px} </style> <body> <table> <tr> <td>우리나라</td> <td>대한민국</td> </tr> </table> </body>"; echo strip_tags($A); ?>
아래같이 출력이 됩니다
타이틀입니다 function test() { alert('1'); } #aaa{width:10px;} #aaa b{border-bottom:1px solid #fff; padding:5px 0 3px 12px} 우리나라 대한민국
그런데 제가 원하는건 본문에 있는
우리나라 대한민국
이것이거든요....
이것이 가능할까요?
Forums:
지금 위에 있는
지금 위에 있는 상황에 한정한다면 body 이전까지 자르고 strip_tags 를 하시면 됩니다.
하지만 일반적인 경우를 처리하려면 php 용 HTML Parser 라이브러리들을 찾아보시셔야 할 것 같습니다.
구글에서 php html dom parser 등으로 검색해 보세요.
댓글 달기