Embedded PHP, cannot stop?
I'm a little bit confused right now. I have this code:
<?php $this->head( ?>
<style type="text/css">
.error {
background-color: #ccc;
border: 1px solid #999;
padding: 10px;
width: 500px;
}
</style>
<?php ); ?>
I was pretty sure that you could do this. It's pretty similar to:
<?php if (true) { ?>
Hei
&开发者_如何学Golt;?php } ?>
In fact an error occurs:
Parse error: syntax error, unexpected ';', expecting ')' in file.php on line 1 (line 1 of the code)
How can i better fix it?
If you are trying to pass the html as a variable then use heredoc.
$var = <<<HTML
<style type="text/css">
.error {
background-color: #ccc;
border: 1px solid #999;
padding: 10px;
width: 500px;
}
</style>
HTML;
$this->head($var);
You cannot do this:
$variable = ?> <p>omgwtfbbq</p> <?;
Thats just isn't a valid syntax.
Insead, you can surround it with quotes (single or double)
$variable = "<p>omgwtfbbq</p>";
Use a HEREDOC for the multiline text.
<?php
$style = <<<EOS
<style type="text/css">
.error {
background-color: #ccc;
border: 1px solid #999;
padding: 10px;
width: 500px;
}
</style>
EOS;
$this->head($style);
?>
You can use HEREDOC syntax with php.
精彩评论