2
[인용구] BBCode를 제외하고 문자열에서 모든 BBCode를 제거 할 수 있기를 원합니다.[인용구]를 제외하고 문자열에서 모든 BBCode를 제거하십시오
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
$quote = preg_replace($pattern, $replace, $tag->content);
[인용구] BBCode를 제외하고 문자열에서 모든 BBCode를 제거 할 수 있기를 원합니다.[인용구]를 제외하고 문자열에서 모든 BBCode를 제거하십시오
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
$quote = preg_replace($pattern, $replace, $tag->content);
을 거의 어떤 솔루션
:[quote="User"]
[quote=User]
[quote]
Text
[/quote]
[/quote]
[/quote]
이 내가 현재 작동의 BBCode를 제거하는 데 사용하는 것입니다 :
나는 따옴표 가능할 수있는 다음과 같은 패턴을 가지고
<?php
function show($s) {
static $i = 0;
echo "<pre>************** Option $i ******************* \n" . $s . "</pre>";
$i++;
}
$string = 'A [b]famous group[/b] once sang:
[quote]Hey you,[/quote]
[quote mlqksmkmd]No you don\'t have to go[/quote]
See [url
http://www.dailymotion.com/video/x9e7ez_pony-pony-run-run-hey-you-official_music]this video[/url] for more.';
// Option 0
show($string);
// Option 1: This will strip all BBcode without ungreedy mode
show(preg_replace('#\[[^]]*\]#', '', $string));
// Option 2: This will strip all BBcode with ungreedy mode (Notice the #U at the end of the regex)
show(preg_replace('#\[.*\]#U', '', $string));
// Option 3: This will replace all BBcode except [quote] without Ungreedy mode
show(preg_replace('#\[((?!quote)[^]])*\]#', '', $string));
// Option 4: This will replace all BBcode except [quote] with Ungreedy mode
show(preg_replace('#\[((?!quote).)*\]#U', '', $string));
// Option 5: This will replace all BBcode except [quote] with Ungreedy mode and mutiple lines wrapping
show(preg_replace('#\[((?!quote).)*\]#sU', '', $string));
?>
실제로 실제로 옵션 3과 5 사이의 선택입니다.
[^]]
은 ]
이 아닌 모든 문자를 선택합니다. 그것은 ungreedy 모드를 "에뮬레이션"할 수 있습니다.U
정규식 옵션 정규식 옵션이(?!quote)
우리가 다음 선택에서 "견적"일치하지 않는 아무 말도 할 수 있도록 여러 행에 일치시킬 수 있습니다 .*
대신s
[^]]*
의 우리가 사용할 수 있습니다. 이 방법으로 사용됩니다 : ((?!quote).)*
. 자세한 내용은 Regular expression to match a line that doesn't contain a word?을 참조하십시오.This fiddle은 실시간 데모입니다.
[PHP의 BBCode 확장] (http://php.net/bbcode)을 사용하십시오. – Gumbo