2013-02-13 2 views
0

전 태그 사이에있는 html 태그를 대체하려고합니다. 이것은 내가하고 싶은 것입니다 :태그 사이에 preg_replace 태그

$str = '<pre><div>Get<p>rid</p> of html tags</div></pre>'; 
$str = preg_replace('#(<pre.*?>)/<[^<>]+>/(</pre>)#', '$1$2', $str); 
echo $str; 
그것은으로 responed해야

사전 태그

내가 아는 사실

에서 "HTML 태그를 제거하기",

$str = preg_replace('#(<pre.*?>).*?(</pre>)#', '$1$2', $str); 

작동하는지 , 빈 사전 태그로 응답합니다.

사전 태그 사이의 모든 HTML 태그를 삭제하면됩니다.

답변

3

는 여기에 내가 그것을 할 거라고 방법은 다음과 같습니다

$str = preg_replace_callback("#(<pre[^>]*>).*?</pre>#is",function($m) { 
    return $m[1].strip_tags($m[0])."</pre>"; 
},$str); 
+0

감사합니다! 나는 내가 여기 일찍 왔으면 좋겠다. 나에게 5 시간을 구해줄 것이다. D – user2067005

0
$str = '<pre><div>Get<p>rid</p> of html tags</div></pre>'; 
if(preg_match("/<pre>(.+?)<\/pre>/i", $str,$res)) 
{ 
    $str=strip_tags($res[1]); 
} 
echo $str;