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

When to use single or double quotes

P: n/a
Hi,

I am still confused as when to use single or double quotes.

This works:

echo "<td>" . $row[0] . "</td>";

and this does not

echo "<td bgcolor="#FFFFFF"><font face="Arial" size="1">" . $row[0] .
"</font></td>";

Regards
Dynamo

Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Dynamo wrote:
Hi,

I am still confused as when to use single or double quotes.

This works:

echo "<td>" . $row[0] . "</td>";

and this does not

echo "<td bgcolor="#FFFFFF"><font face="Arial" size="1">" . $row[0] .
"</font></td>";

Try
echo "<td bgcolor=\"#FFFFFF\"><font face=\"Arial\" size=\"1\">" . row[0]

When using the same type of quotes in a string containing the same quote
type, you need to escape the characters with a backslash \

or

echo '<td bgcolor="#FFFFFF"><font face="Arial" size="1">' . $row[0]

Jul 17 '05 #2

P: n/a
David Zawislak wrote:
Dynamo wrote:
Hi,

I am still confused as when to use single or double quotes.

This works:

echo "<td>" . $row[0] . "</td>";

and this does not

echo "<td bgcolor="#FFFFFF"><font face="Arial" size="1">" . $row[0] .
"</font></td>";


Try
echo "<td bgcolor=\"#FFFFFF\"><font face=\"Arial\" size=\"1\">" . row[0]

When using the same type of quotes in a string containing the same quote
type, you need to escape the characters with a backslash \

or

echo '<td bgcolor="#FFFFFF"><font face="Arial" size="1">' . $row[0]


Also single quotes don't parse variables in the quoted strings nor
escape sequences.

To place variables into your string to be parse, use double quotes.

$x = 5;
echo '$x' . "= $x \n";
Jul 17 '05 #3

P: n/a
Dynamo <Dy***********@newsguy.com> wrote:
Hi,

I am still confused as when to use single or double quotes.

This works:
echo "<td>" . $row[0] . "</td>";
I'm also relatively new in php, but have learned that...
1st double qote start your html code, 2nd ends it.
and this does not

echo "<td bgcolor="#FFFFFF"><font face="Arial" size="1">" . $row[0] .
"</font></td>";


here, you are printing in html:
<td bgcolor=
and then you are telling to php:
#FFFFFF and that php doesn't understand

you have to use backslash so php will know this isn't end of your "html
part", rather is a "part of html":

echo "<td bgcolor=\"#FFFFFF\"><font face=\"Arial\" size=\"1">" . $row[0]
.. "</font></td>";

btw, it is much better to learn and use css instead of placing those
font tags in html.
also, on the end (to have clearer html code) use \n at the and of line:
....</font></td>\n";

and, I dont think you have to break your html line to put your variable
in... this should work to:

echo "<td bgcolor=\"#FFFFFF\"><font face=\"Arial\"
size=\"1">$row[0]</font></td>\n";

....and the best:
<td class=\"arial1\">$row[0]</td>\n";

(however, as I'm not an expert, we will have to vait for someone
cleverer to tell if that [0] needs to be in some quotes or not...)
--
Jan ko?
http://fotozine.org
--
Jul 17 '05 #4

P: n/a
Dynamo wrote:
I am still confused as when to use single or double quotes. echo "<td bgcolor="#FFFFFF"><font face="Arial" size="1">" . $row[0] .

^^^^^^^^^ ^^^^^^^ ^^^
Quotes within quotes.

Either you 'escape' them or use single quotes.

Read http://www.php.net/manual/en/language.types.string.php
and try these examples.

echo "He said "WOW" when he saw it.";
echo "He said 'WOW' when he saw it.";
echo "He said \"WOW\" when he saw it.";
echo "He said \'WOW\' when he saw it.";

/* or with sinle quotes */
echo 'He said "WOW" when he saw it.';
echo 'He said 'WOW' when he saw it.';
echo 'He said \"WOW\" when he saw it.';
echo 'He said \'WOW\' when he saw it.';

/* or with embedded variables */
$x = 'foobar';
echo "x is $x";
echo 'x is $x';

--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Jul 17 '05 #5

P: n/a
I noticed that Message-ID: <1g****************************@mail.dot>
from JaNE contained the following:
...and the best:
<td class=\"arial1\">$row[0]</td>\n";


Mmm, not quite. The class should ideally unambiguously describe the
section of the document e.g class="product_table_item"

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6

P: n/a
Geoff Berrow <bl******@ckdog.co.uk> wrote:
I noticed that Message-ID: <1g****************************@mail.dot>
from JaNE contained the following:
...and the best:
<td class=\"arial1\">$row[0]</td>\n";


Mmm, not quite. The class should ideally unambiguously describe the
section of the document e.g class="product_table_item"


it is off-topic here, but, why on earth (if you like) not to describe
some formating with css? assume you have some form and after validating
data, you want to show that something is wrong with red background?
(disgusting, but if someone like it...)

--
Jan ko?
http://fotozine.org
--
Jul 17 '05 #7

P: n/a
I noticed that Message-ID: <1g**************************@mail.dot> from
JaNE contained the following:
Mmm, not quite. The class should ideally unambiguously describe the
section of the document e.g class="product_table_item"


it is off-topic here, but, why on earth (if you like) not to describe
some formating with css? assume you have some form and after validating
data, you want to show that something is wrong with red background?
(disgusting, but if someone like it...)


It is possible to define a lot of css classes to cover every eventuality
arial_bold, arial_bold_red, arial_itallic_bold_red and so on. Then
whenever you wanted to style something pick from the list. But it's a
terrible idea. You would have no idea what type of elements these
classes are being applied to and changing the look of a site would still
involve editing every single site page!

The idea of CSS is to promote consistency. Therefore it is better to
name the classes after the parts of the document they cover, e.g.
preamble, chapter_heading, chapter_subheading etc. Then if you decided
to change the look of one particular element, simply change the CSS and
it is changed throughout the site. If you want a high contrast version,
simply change the CSS, no problem.

See www.csszengarden.com
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8

P: n/a
Geoff Berrow <bl******@ckdog.co.uk> wrote:
It is possible to define a lot of css classes to cover ... But it's a
terrible idea. ...
The idea of CSS is to promote consistency. ...


of course, of course, of course... reason why I wrote class=\"arial1\"
wasn't suggestion to have specific class for each and every think on
page, just kind of description that he can create css class with
definition of font and size.
I don't like to use too meny classes or ids in my css file, depending on
kind of website, 10 to 20 basic definitions. of course, each can have
'subdefinitions' (like "div#links a:hover") but that is another
storry...

--
Jan ko?
http://fotozine.org
--
Jul 17 '05 #9

P: n/a
.oO(JaNE)
...and the best:
<td class=\"arial1\">$row[0]</td>\n";


Even better (no ugly escaping, single quotes are allowed in HTML):

echo "<td class='arial1'>$row[0]</td>\n";

Micha
Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.