string = "(KEY)anything (KEY)anything (A)anything (KEY)anything";
이어야합니다.
string = "<p>anything</p> <p>anything</p> (A)anything <p>anything</p>";
string = "(KEY)anything (KEY)anything (A)anything (KEY)anything";
이어야합니다.
string = "<p>anything</p> <p>anything</p> (A)anything <p>anything</p>";
$result = preg_replace('/\(KEY\)(\w+)/', '<p>\1</p>', $subject);
이 예제에 적용됩니다.
anything
개 이상의 단어가 될 수 있으며, "(KEY)
후 아무것도 다음 여는 괄호 앞에"로 정의됩니다, 당신은 preg_replace이다 (http://php.net을
$result = preg_replace('/\(KEY\)([^(]+)/', '<p>\1</p>', $subject);
체크 아웃 사용할 수있는 경우 /manual/en/function.preg-replace.php)
$pattern = '\(KEY\)(\w+)\s';
$replacement = '<p>$1</p>';
$string = preg_replace($pattern,$replacement,$string);
그런 식으로 작동해야합니다.
시작하는 방법을 모르는 경우, 여기에 정규 표현식에 대한 훌륭한 입문서입니다
또한 도구는 당신이 그들을 공예 도움이 좋은 (무료)가 있습니다 Learning Regular Expressions
:
https://stackoverflow.com/questions/89718/is-there-anything-like-regexbuddy-in-the-open-source-world
무엇을 시도 했습니까? 이제는 마치 코드 작성을 요청하는 것과 같습니다. –
난 그냥 정규식 구문이 필요 – faressoft
원래 문자열 정말 html입니까? 그렇다면 html 파서를 고려하십시오. – marcog