가능한 중복 : 나는 정규식에 문제가
php regex [b] to <b>정규식 중첩 포럼 따옴표 (BBCode는)
, 나는 절대 정규식 멍청한 놈입니다. HTML을 'BBCode'로 다시 변환하려고 할 때 잘못된 점이 있는지 알 수 없습니다.
누군가 'unquote'함수를 살펴보고 내가 작성한 명백한 실수를 말할 수 있습니까? (나는 명백하지 않은 오류를 항상 발견하기 때문에 분명하다.)
참고 : Regex를 재귀 적으로 사용하지는 않는다. 내 머리를 감당할 수 없어 이미 인용문을 정렬하는 방식으로 시작했다. 그들은 중첩되어 있습니다. 샘, 사전에
<html>
<head>
<style>
body {
font-family: sans-serif;
}
.quote {
background: rgba(51,153,204,0.4) url(../img/diag_1px.png);
border: 1px solid rgba(116,116,116,0.36);
padding: 5px;
}
.quote-title, .quote_title {
font-size: 18px;
margin: 5px;
}
.quote-inner {
margin: 10px;
}
</style>
</head>
<body>
<?php
$quote_text = '[quote=VCMG][quote=2xAA]DO RECURSIVE QUOTES WORK?[/quote]I have no idea.[/quote]';
$quoted = quote($quote_text);
echo $quoted.'<br><br>'.unquote($quoted); ?>
</body>
감사 :
<?php
function quote($str){
$str = preg_replace('@\[(?i)quote=(.*?)\](.*?)@si', '<div class="quote"><div class="quote-title">\\1 wrote:</div><div class="quote-inner">\\2', $str);
$str = preg_replace('@\[/(?i)quote\]@si', '</div></div>', $str);
return $str;
}
function unquote($str){
$str = preg_replace('@\<(?i)div class="quote"\>\<(?i)div class="quote_title"\>(.*?)wrote:\</(?i)div\><(?i)div class="quote-inner"\>(.*?)@si', '[quote=\\1]\\2', $str);
$str = preg_replace('@\</(?i)div\></(?i)div\>@si', '[/quote]', $str);
}
?>
이 그것을 테스트하는 데 도움 그냥 코드입니다.
> 그 빌어 먹을 반환 ... 나는 그것이 명백한 무엇인가 알았다. 단순화에 감사드립니다. 훨씬 더 좋습니다! – 2xAA