< 코드 내에서 내용에 대해서만 htmlentities()를 실행하고 싶습니다. </코드 ><code></code>에서만 PHP htmlentities!
문자열을 취하여 < 코드 사이의 내용을 찾는 함수를 작성했습니다. > </code >
function parse_code($string) {
// test the string and find contents with <code></code>
preg_match('@<code>(.*?)</code>@s', $string, $matches);
// return the match if it succeeded
if($matches) {
return $matches[1];
}else {
return false;
}
}
그러나 실제로 htmlentities()를 실행할 함수에 대한 도움이 필요합니다. < 코드 > </코드 > 내의 내용에 다음 implode() 모든 다시 함께. 예를 들어 아래 문자열이 있다고 가정 해 보겠습니다.
<div class="myclass" rel="stuff"> things in here </div> <code> only run htmlentites() here so strip out things like < > " ' & </code> <div> things in here </div>
다시 한번이 함수는 문자열의 모든 내용을 동일하게 유지해야하지만 < 코드의 내용에 대해 htmlentities() 만 수정하고 실행해야합니다. > </code >
이 글을 읽는 것이 좋습니다 - http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Phil
@phil ahh very interesting. – kr1zmo