Re: Variable substitution in HTML
| From: | Christopher William Wesley | Date: | Wed, 17 Oct 2001 21:40:54 +0000 |
| Subject: | Re: Variable substitution in HTML | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71409@lists.php.net to get a copy of this message | ||
You can print in here-doc style w/ PHP4.
For example ....
<?php
$myname = "Chris";
$yourname = "Chris too";
print <<<EOF
<html>
<head>
<title>Names</title>
</head>
<body>
<p>My name is ${myname}<br>
Your name is ${yourname}</p>
</body>
</html>
EOF;
?>
The 'print <<<EOF' and the UNINDENTED 'EOF;' work the magic.
DON'T INDENT
THE 'EOF;'!!!
I use braces around the variable name so as to not get it entwined with
the HTML. It makes it less confusing (possible!) to do things like
<p>The file is here: ${path}/${fileBaseName}01.txt</p>
For reference: "heredoc syntax"
http://www.php.net/manual/en/language.types.string.php
g.luck,
~Chris /"\
\ / September 11, 2001
X We Are All New Yorkers
/ \ rm -rf /bin/laden
On Wed, 17 Oct 2001, barlow wrote:
> Is there a simple way of converting PHP variables in HTML?
> e.g. I have HTML:
>
> <P> My name is $myname </P>
>
> Is there a conversion method that doesn't require further changes to the
> HTML (to avoid adding <?= $myname ?> each time, for instance), and
> that doesn't require knowledge of variable names (e.g. ereg_replace).
>
> In a Unix shell I once sourced an HTML file, that led to correct shell
> variable substitution - but what about under Windows ?
>
> Thanks,
> Chris
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>