2017-12-14 08:05
浏览 101


I have a function which compares emails contents from a few tables. If the contents differ, I want to display it for comparison. I am trying to do that using iframes and srcdoc attribute. This is a fragment of my email which has got inline styles and nested quotes.

<html xmlns="http://www.w3.org/1999/xhtml">
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <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">

I tried to replace all quotes with that function.

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

but it does not work. I have also tried




but it also did not work. How can i display email content in an iframe properly?

图片转代码服务由CSDN问答提供 功能建议

我有一个函数可以比较几个表中的电子邮件内容。 如果内容不同,我想显示它以进行比较。 我试图使用 iframes srcdoc 属性来做到这一点。 这是我的电子邮件的一个片段,它有内联样式和嵌套引号。

 &lt; html xmlns =“http://www.w3.org/1999/xhtml”&gt; 
&lt; head&gt; 
&lt; meta content =“  text / html; charset = UTF-8“http-equiv =”Content-Type“/&gt; 
&lt; title&gt;标题&lt; / title&gt; 
&lt; / head&gt; 
&lt; style type =”text /  css“&gt; a:已访问{color:#fff;}&lt; / style&gt; 
&lt; body style =”background:#fff; margin-top:25px; margin-bottom:30px; padding-top:0;  padding-bottom:0;“&gt;&amp; nbsp; 
&lt; table align =”center“&gt; 

我试图将所有引号替换为 功能。

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


  htmlentities($ row1 ['  email_content'])

  addslashes($ row1 ['email_content'])

但它也不起作用。如何正确显示 iframe 中的电子邮件内容?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqd82461 2017-12-14 09:21

    I was curious about this so knocked up a couple of quick test pages to test for myself what you were saying ~ seems obvious but whatever character is used with srcdoc ( ie: srcdoc=' or srcdoc=" ) must be escaped/replaced when generating the content.

    <!-- mickeymouse.html ~ used as source for `srcdoc` -->
            <title>Mickey Mouse loved Minnie</title>    
            <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>
    <!-- iframe page - will display mickeymouse.html -->
            <title>iframe - srcdoc</title>  
                $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>
    打赏 评论

相关推荐 更多相似问题