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 (< ;, > ;) 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("<", "<", "$rawcode");
$code = str_replace(">", ">", "$code1");
echo $code1;
?>
<!--<p>Create your page here.</p>-->
</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”