2017-12-14 13 views
0

私はいくつかのテーブルの電子メールの内容を比較する機能を持っています。 内容が異なる場合は、比較のために表示する必要があります。私はiframessrcdoc属性を使ってそれをしようとしています。これは私の電子メールの断片で、インラインスタイルとネストされた引用符を持っています。iframeに関する問題

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> 
     <title>Title</title> 
    </head> 
    <style type="text/css">a:visited {color: #fff;}</style> 
    <body style="background: #fff; margin-top:25px; margin-bottom:30px; padding-top:0; padding-bottom:0;">&nbsp; 
     <table align="center"> 

すべての引用符をその機能で置き換えようとしました。

str_replace([ '"', '&' ], [ '&quot;', '&amp;amp;' ],$row1['email_content']) 

しかし、動作しません。私はまた、

htmlentities($row1['email_content']) 

addslashes($row1['email_content']) 

を試してみましたが、それはまた、うまくいきませんでした。 iframeのメールコンテンツを正しく表示するにはどうすればよいですか?

+0

*「どのように私は適切にiframe内emialコンテンツを表示することができます」* - いけない[DOMドキュメントまたはそのようでコンテンツを解析する]の代わりに、わざわざ(https://stackoverflow.com/questions/3577641/how-do -you-parse-and-process-html-xml-in-php) - あなたの質問もほとんど意味がなく、引用符付きかどうかにかかわらずiframeに正しく表示されます。クォートすると、HTMLが破られます –

+0

str_repalceを指定しないと何も表示されません。 str_replaceでプレーンテキストが表示されます。 – newman

+0

どのようにhtmlをiframeに追加していますか? – RamRaider

答えて

1

私はこのことについて興味があったので、あなたが言っていたものを自分のためにテストするために迅速なテストページのカップルをアップノック〜(すなわち:srcdoc='またはsrcdoc=")明白なようだが、srcdocで使用されているものの文字が生成するときに交換/エスケープする必要がありますコンテンツ。

<!-- mickeymouse.html ~ used as source for `srcdoc` --> 

<html> 
    <head> 
     <title>Mickey Mouse loved Minnie</title>  
    </head> 
    <body> 
     <h1>Mickey Mouse</h1> 
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam non finibus nisl. Etiam ut velit ut est placerat dictum. </p> 

     <!-- content populated by inline javascript within iframe srcdoc html --> 
     <div id="donaldduck">nothing to see here</div> 

     <script>document.getElementById("donaldduck").innerHTML="poor wiley coyote, when will he catch that damn bird?";</script> 


     <!-- The line below caused the iframe to not correctly render before doing str_replace to edit the single quotes --> 
     <p>If this text has a single quote - like ' it will cause whatever follows to not render and breaks the `srcdoc` content</p> 

    </body> 
</html> 



<!-- iframe page - will display mickeymouse.html --> 
<html> 
    <head> 
     <title>iframe - srcdoc</title> 
    </head> 
    <body> 
     <?php 
      $file='mickeymouse.html'; 
      $html=file_get_contents($file); 
      /* 

       ' -> &#39; 
       " -> &#34; 

      */ 

     ?> 
     <iframe srcdoc="<?php echo str_replace('"', '&#34', $html); ?>" width=800 height=600 sandbox='allow-forms allow-scripts allow-same-origin'></iframe> 
    </body> 
</html> 
関連する問題