正在编写的部分HTML格式的文本

时间:2013-01-11 03:37:58

标签: php html file text fwrite

我有一个有趣的问题。我的代码低于$_POST['content']$_POST['page']。尝试编写的“内容”是“HTML”(见下文)但是,实际编写的内容是

<footer> 
        <div class="grid_16"> 
                <div class="wrapper"> 
                        <span class="right"><!-- {%FOOTER_LINK} --></span>

即:大部分内容都缺失。

任何指导都将不胜感激

<?php

if (!$_POST['content'] && !$_POST['page'])
    return false;

$content = $_POST['content'];
$page = $_POST['page'];

$fp = fopen('content/'.$page, 'w');

fwrite($fp, htmlspecialchars($content));

fclose($fp);

?>

$_POST['content']是:

<footer> 
    <div class="grid_16"> 
        <div class="wrapper"> 
            <span class="right"><!-- {%FOOTER_LINK} --></span> l
            la-panacee &copy; 2013 &nbsp;|&nbsp; 
            <a href="privacyStatement.php">Privacy policy</a>
        </div> 
    </div>
 </footer>

1 个答案:

答案 0 :(得分:0)

截断HTML的原因可能是因为$ _POST变量中存在未编码的&符号。

<强> RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax

2.2. Reserved Characters

   Many URI include components consisting of or delimited by, certain
   special characters.  These characters are called "reserved", since
   their usage within the URI component is limited to their reserved
   purpose.  If the data for a URI component would conflict with the
   reserved purpose, then the conflicting data must be escaped before
   forming the URI.

      reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","

   The "reserved" syntax class above refers to those characters that are
   allowed within a URI, but which may not be allowed within a
   particular component of the generic URI syntax; they are used as
   delimiters of the components described in Section 3.