[thelist] Php Heredoc syntax
David Bindel
dbindel at austin.rr.com
Thu Jul 31 20:01:55 CDT 2003
thelist-bounces at lists.evolt.org wrote:
> This does not work... and I haven't found the culprit.
> Here is the browser content which contains an error message:
>
> Parse error: parse error, unexpected T_SL in
> /home/httpd/vhosts/sportsmenafield.com/httpdocs/xarahost/inclu
> de1.php on line 13 Hello World
>
> Here is the 'Source code in the browser:
>
> <br />
> <b>Parse error</b>: parse error, unexpected T_SL in
> <b>/home/httpd/vhosts/sportsmenafield.com/httpdocs/xarahost/in
> clude1.php</b> on line <b>13</b><br />
>
> Hello World
Hi Russell,
I copied the code you posted, and the page didn't give me any errors at
all. However, you should be aware that you cannot embed <?php ?> tags
in Heredocs since Heredocs are parsed by PHP exactly the same way
double-quoted PHP strings are.
For example,
$html = <<<END
<html>
<head>
<title>Sportsmen Afield| >Zarahost/index1.php
<?php
echo($title);
?></title>
</head>
END;
Outputs as
<html>
<head>
<title>Sportsmen Afield| >Zarahost/index1.php
<?php
echo($title);
?></title>
</head>
*literally* - <?php echo($title); ?> is not parsed since it is part of
the string, although $title is parsed as a PHP variable (but it's an
empty string "" using the code you posted.)
HTH,
David
--
David I. Bindel
Website Development
dbindel at austin.rr.com
www.davidbindel.com
More information about the thelist
mailing list