【问题标题】:How do I not detect quotation marks when putting html into a string in php? [duplicate]将html放入php中的字符串时如何检测不到引号? [复制]
【发布时间】:2014-12-12 00:10:58
【问题描述】:

标题说明了一切,它检测 HTML 中的引号。我怎样才能让它不这样做?

$html = fopen($videoname."/video.html", "w") or die("Unable to Play Video");
$txt = "<html><body><video width="1000" controls>
    <source src="video.mp4" type="video/mp4">
    Your browser does not support HTML5 video.
</video></body></html>";
fwrite($html, $txt);
fclose($html);

【问题讨论】:

    标签: php html escaping


    【解决方案1】:

    正如胜利者所说,或者:

    $txt = '<html><body><video width="1000" controls>
        <source src="video.mp4" type="video/mp4">
        Your browser does not support HTML5 video.
    </video></body></html>';
    

    或

    $txt = <<<EOT
    <html><body><video width="1000" controls>
        <source src="video.mp4" type="video/mp4">
        Your browser does not support HTML5 video.
    </video></body></html>
    EOT;
    

    【讨论】:

    【解决方案2】:

    您需要“转义”引号。请尝试以下操作:

    $txt = "<html><body><video width="1000" controls>
        <source src=\"video.mp4\" type=\"video/mp4\">
        Your browser does not support HTML5 video.
    </video></body></html>";
    

    【讨论】:

    • 像魅力一样工作,谢谢。
    【解决方案3】:

    这称为字符串转义

    $html = fopen($videoname."/video.html", "w") or die("Unable to Play Video");
    $txt = "<html><body><video width='1000' controls>
        <source src='video.mp4' type='video/mp4'>
        Your browser does not support HTML5 video.
    </video></body></html>";
    fwrite($html, $txt);
    fclose($html);
    

    在你用双引号“”打开你的块的地方,必须使用单引号''转义其中的任何属性,反之亦然。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 2011-07-02
      • 2011-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多