php
  • regex
  • iframe
  • strip
  • 2012-02-15 2 views 0 likes 
    0

    나는 XML 파일을 처리하지있어 때로는 "iframe을"내가 나갈 필요가 및 "스크립트" 태그, 심지어 'XML- 전에이있다 parse-it 'PHP 스트립 iframe을 스크립트 태그 (더를 htmlentities())

    나는 정규 표현식을 시도하고 있지만 잘못 알고있다! :(

    테스트 문자열 :

     $teststring = 'p><iframe src="http://www.facebook.com/plugins/like.php?href=abcdef&layout=standard&show_faces=false&width=450&action=like&colorscheme=dark&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowtransparency="true"></iframe></p>'; 
    
    //todo clean this up// found this function on net. //more legacy stufff 
        $Rules = array(
         '@<script[^>]*?>.*?</script>@si', // Strip out javascript     
         '@&(cent|#162);@i', // Cent 
         '@&(pound|#163);@i', // Pound 
         '@&(copy|#169);@i', // Copyright 
         '@&(reg|#174);@i', // Registered 
         '@&#(d+);@e', // Evaluate as php 
    ---> PROBLEM--> '@&lt;iframe [^&lt;]&lt;.*?&lt;\/iframe&gt;@i', 
    
        ); 
    
        $Replace = array(
         '', 
         chr(162), 
         chr(163), 
         chr(169), 
         chr(174), 
         'chr()', 
         '', 
    
        ); 
         //expecting <p></p> 
        $data = preg_replace($Rules, $Replace, $teststring); 
    
    
          echo $data; 
    

    답변

    1

    그냥이

    '@&lt;iframe(?:(?!&gt;).)*&gt;.*?&lt;\/iframe&gt;@i' 
    
    +0

    멋진 :) 감사하십시오! – user914584

    +0

    최고급 .... 당신은 화격자입니다. :) –

    +0

    고맙습니다 .... :) @lake –

    관련 문제