473,410 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

When to use single or double quotes

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
9 2639
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
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
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
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
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
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
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
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
.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
12
by: Joshua Beall | last post by:
Hi All, I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards...
11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
2
by: girish | last post by:
In my XML document, some node attributes data contains both single quot and double quote characters, such as <input msg="Hello "World", What's up"/>. The double quotes are in form of escape...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
1
by: desi.american | last post by:
I have a dynamically generates ASPX page with tables and data. Depending on user selection, the same page can be viewed as a simple web page (rendered in HTML) or as an excel spreadsheet. If the...
0
NeoPa
by: NeoPa | last post by:
Background Whenever code is used there must be a way to differentiate the actual code (which should be interpreted directly) with literal strings which should be interpreted as data. Numbers don't...
2
by: Reporter | last post by:
I got the following example from http://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/index.html : echo '<tr><td>First name:</td><td><input type="text" name="first_name"...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.