Insert HTML from SQL into textarea?

I would like to know why I am getting a "Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING" in my code, which pulls HTML off an MySQL database, replaces < and > with the entity (&lt ;, &gt ;) and inputs it into a textarea (CKEditor). Here is that section of the code:

<textarea name="editor1">
          <?php
            //QUERY DATABASE
            $query1 = "SELECT * FROM users WHERE ID = '" . $id . "'";
            $resource1 = mysql_query($query1, $database);
            $result1 = mysql_fetch_assoc($resource1);
            $rawcode = $result['code'];
            $code1 = str_replace("<", "&lt;", "$rawcode");
            $code = str_replace(">", "&gt;", "$code1");
            echo $code1;          
          ?>
    <!--&lt;p&gt;Create your page here.&lt;/p&gt;-->
</textarea>

you have an extra "" at the end of line

$rawcode = $result['code'];

remove it


不要试图自己逃避HTML,而是使用htmlspecialchars()。


$rawcode = $result['code'];

backslash is escape char in php, and escaping $ in next line. PHP parse $code1 as string that is not allowed here.

you shouldn't also use $rawcode, and $code1 in "", because it only slows slightly execution.

链接地址: http://www.djcxy.com/p/69870.html

上一篇: 语法错误:第1行出现意外的“&lt”

下一篇: 将SQL中的HTML插入到textarea中?