You are here: Re: single quote in string constant « PHP Language « IT news, forums, messages
Re: single quote in string constant

Posted by MangroveRoot on 12/02/07 23:09

Allodoxaphobia wrote:
>>
>> At the very top of my .php file, I define a variable as follows:
>> ======
>> $title = "Doesn't Matter";
>
> Not tested:
>
> $title = "Doesn't Matter";

This helps a great deal.
A *little* ugly, but only ugly in one place, not *everywhere*.
The explanation (as I see it) is that this ensures that
the punctuation mark indicating the contraction of "does not"
is an apostrope (which, grammatically, it's *supposed* to be)
and not just a singlequote
(which *happens* to look the same in most, if not all, fonts).

I then went on to use this:
======
<?php echo "
<H1><IMG SRC='_images/_rock/Zacs World.gif' ALT='{$title}'></H1>
"; ?>
------
and it worked perfectly, demonstrating that the apostrophe
is not mistaken for a singlequote, and the two do not interact.

I went on further to use this:
======
<?php echo "
<H1><IMG SRC=\"foo.gif\" ALT=\"{$title}\"></H1>
"; ?>
------
This way, the *generated* HTML has the more pleasing
(and, I gather, more backward-compatible) format.
The business of escaping all the doublequotes inside the quoted string
*does* get old after a while -- tiresome to do, prone to error, and ugly --
but it seems to be what most scripting languages do.

(Perl, sed, TECO, and probably others
allow the programmer to specify an alternate character
to quote the entire string, so that ordinary single *or* double quotes
may be used inside the string with impunity.)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация