wilson's story

html 변환해주기 본문

PHP

html 변환해주기

wilson 2008. 4. 7. 14:20
반응형
$search = array ("']*?>.*?'si",
                 "'<[\/\!]*?[^<>]*?>'si",
                 "'([\r\n])[\s]+'",
                 "'&(quot|#34);'i",
                 "'&(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");

$replace = array ("",
                  "",
                  "\\1",
                  "\"",
                  "&",
                  "<",
                  ">",
                  " ",
                  chr(161),
                  chr(162),
                  chr(163),
                  chr(169),
                  "chr(\\1)");

$text = preg_replace($search, $replace, $content);

데이터베이스에 html 코드가 특수기호로 풀어서 들어갔을경우 사용한다
특히 fckeditor를 사용하고 값을 가져올때 사용하면 유용!!
반응형