----- Original Message -----
From: "brucewhealton"
<snip>
Ok, I'm a bit confused on the single and double quotes. If single
quotes does not replace the variable, then how would this work:
echo('<img src="images/topbanner' . $number. '.jpg" />');
The first choice from below? Would that work with the single quotes?
I see that this would work:
print "<img src='images/topbanner$number.jpg' />";
I thought I was going to have to worry about escaping the < > and "
characters but none of these solutions require that. Why?
Thanks,
Bruce
------------------------------------
Hello Bruce,
Someone mentioned that strings encapsulated in double quotes
are parsed for
variables etc only in print and echo primates however I seem to remember the
same parsing when using
the eval function so I suspect that this parsing exists for all strings
encapsulated in double
quotes.
My general rule is to use literal quotes ' for everything that does not need to
be parsed -
$_SERVER['PHP_SELF']
echo('<table border="1">' . "\n");
I also use only double quotes in HTML that is sent as output.
To escape things in double quotes -
\" - double quote
\r - return
\n - new line
> If single quotes does not replace the variable, then how would this work:
> echo('<img src="images/topbanner' . $number. '.jpg" />');
The variable is not within quotes as the first quote is closed by a quote of
the same type.
> Would this work with the single quotes?
> print "<img src='images/topbanner$number.jpg' />";
This - below will not work because the variable is within single quotes -
print '<img src='images/topbanner$number.jpg' />';
In fact it would cause an error
> I see that this would work:
> print "<img src='images/topbanner$number.jpg' />";
yes and another way to write it is -
print "<img src=\"images/topbanner$number.jpg\" />";
But these only work because of the dot before jpg and without this dot php
would be looking for the
variable $numberjpg
> I thought I was going to have to worry about escaping the < > and "
> characters but none of these solutions require that. Why?
< and > do not need escaping in php as the php open and close tags are <?php
and ?>
< and > are only different for HTML as they are opening and closing tags there
and hence < >
A double quote only needs to be escaped when a string is encapsulated in double
quotes otherwise it
would terminate the string prematurely