문제

I have the code like this:

$data='<p>text begin</p>
<script type="text/javascript">
$(".idr").hide();
$("[rel=tooltip]").tooltip({ placement: "top"});
</script>
<p>text finish</p>';

I'm trying to remove below text:

<script type="text/javascript">
$(".idr").hide();
$("[rel=tooltip]").tooltip({ placement: "top"});
</script>

with preg_replace()

echo preg_replace("/<script(.+?)script>/i", '', $data);

But it's doesn't work. Any suggestions?

도움이 되었습니까?

해결책

If you are tring to remove the script try this:

preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $data);

다른 팁

Just add multiline modifier:

echo preg_replace("/<script(.+?)script>/si", '', $data);
//                               here __^
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top