When I tried to use file_put_contents creat html file with php mysql, I met some trouble. my code as below, some wrong occured in the first echo line. Need some help. thanks.
The error I get is
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
In this line
$php = "echo '<div class=\"title\">'.htmlspecialchars($row['title'],UTF-8).'</div><br />';
Here is the rest of my code
header('Content-type:text/html; charset=utf-8');
set_time_limit(30);
require_once dirname(__FILE__) . '/conn.php';
mysql_select_db("ba_10978243",$handle_db5);
$result = @mysql_query("SELECT title,content,date FROM new_heelp Order By date DESC LIMIT 15");
while ($row = @mysql_fetch_array($result))
{
$php = "echo '<div class=\"title\">'.htmlspecialchars($row['title'],UTF-8).'</div><br />';//echo wrong in this line : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
$data = date(\"w j n Y H:i:s\", $row['date']);
echo '<div class=\"date\">'.$data.'</div>';
if(!empty($row['content'])){
echo '<div class=\"content\">'.$row['content'].'</div>';
}";
}
file_put_contents("$article_20100421_132.html", $php);
?>
$php = ''
instead of$php .= ''
. You're not concatenating the string at all – JohnP Apr 21 '11 at 9:46Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
– yuli chika Apr 21 '11 at 9:49