By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

How do you interpret single quote embedded in double quote embedded in single quote?

P: n/a
I got the following example from http://www.evolt.org/article/User_Fr...144/index.html
:

echo '<tr><td>First name:</td><td><input type="text" name="first_name"
value="'.htmlspecialchars($_POST['first_name']).'"></td></tr>';

What purpose do the single quotes serve in
value="'.htmlspecialchars($_POST['first_name']).'"

I don't mean the single quotes around first_name. I mean the single
quotes before and after the periods.

Jul 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jul 28, 9:33 am, Reporter <TruckSaf...@gmail.comwrote:
I got the following example fromhttp://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/inde...
:

echo '<tr><td>First name:</td><td><input type="text" name="first_name"
value="'.htmlspecialchars($_POST['first_name']).'"></td></tr>';

What purpose do the single quotes serve in
value="'.htmlspecialchars($_POST['first_name']).'"

I don't mean the single quotes around first_name. I mean the single
quotes before and after the periods.
Never mind. I figured it out.

Jul 28 '07 #2

P: n/a
On Jul 28, 11:33 am, Reporter <TruckSaf...@gmail.comwrote:
I got the following example fromhttp://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/inde...
:

echo '<tr><td>First name:</td><td><input type="text" name="first_name"
value="'.htmlspecialchars($_POST['first_name']).'"></td></tr>';

What purpose do the single quotes serve in
value="'.htmlspecialchars($_POST['first_name']).'"

I don't mean the single quotes around first_name. I mean the single
quotes before and after the periods.
I am by no means a PHP expert, but I believe you are being misled by
an assumption. The assumption that something is wrong about the single
quotes. That's not the case.
What you have here is a single quoted string that is concatinated to
the result of the htmlspecialchars function, which in turn is
concatinated to another single quted string.
To make thsi clearer remember that the period (.) is the
concatination operator is PHP.

The quotes that are embeded in the strings are the double quotes
(")and the reason for them is that they are required by the html
that is being echoed out.

Finally, the single quotes around the 'first_name' are not embeded
in any string, they are there to make the string 'first_name' the key
(or index) to get thea appropriate value out of the $_POST[] array.
HTH,
- Tom Z
Jul 28 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.