preg_replace() 구문은 정규식을 활용하여
PHP 변수 값 안에 더이상 필요 없는 문자열을 지우는 내장함수입니다.
// 스타일 삭제 처리
$content = preg_replace('/<style\b[^>]*>([\s\S]*?)<\/style>/i', '<!--<style>$1</style>', $content);
$content = str_replace('<!--<!--<style', '<!--<style', $content);$content 에 <style> 태그가 들어있는 경우 주석처리를 진행합니다.
// 스타일 삭제 처리
$wr_content = preg_replace('/<style\b[^>]*>([\s\S]*?)<\/style>/i', '', $wr_content);스타일 태그가 있는 경우 내용을 아예 삭제하는 방법입니다.
다른 태그를 기입하시면 해당 태그 내용도 전부 삭제가 가능합니다.
$bufferString = preg_replace('/\r\n|\r\n/', '', $buffer);
$bufferString = preg_replace("/<em class=\"num\">/", "", $bufferString);
$buffer = preg_replace('/\r\n|\r\n/', '', preg_replace("/<em class=\"num\">/", "", $buffer));$string = "I have 5 apples and 3 oranges";
$pattern = '/\d+/';
$replacement = '';
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string;
// I have apples and oranges$string = "Visit my website at https://www.example.com";
$pattern = '/(https?:\/\/[\S]+)/i';
$replacement = '<a href="$1">$1</a>';
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string;
// Visit my website at <a href="https://www.example.com">https://www.example.com</a>$string = "Hello World!";
$pattern = '/World/';
$replacement = 'PHP';
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string;
// Hello PHP!
<?php
$view['wr_content'] = preg_replace('/<style\b[^>]*>([\s\S]*?)<\/style>/i', '<!--<style>$1</style>-->', $view['wr_content']);
?>