Reply to Re: single quote in string constant

Your name:

Reply:


Posted by Steve on 12/07/07 13:02

MangroveRoot <zcukpkn02@sneakemail.com> wrote in
news:GTD4j.3905$xB.1284@trndny06:

> I've looked in various manuals and tutorials,
> and they cover the obvious situations, but not this one:
>
> At the very top of my .php file, I define a variable as follows:
> ======
> $title = "Doesn't Matter";
> ------
> Note the apostrophe (or, single quote) in the string value.
>
> Further down, in the <HEAD>...</HEAD>, I have the following:
> ======
> <?php
> echo "<TITLE>";
> echo $title;
> echo "'</TITLE>";
> ?>
> ------
> If I bookmark the page, the name is what I hoped: "Doesn't Matter".
>
> Further down, in the <BODY>...</BODY>, I have the following:
> ======
> <?php echo "
> <H1><IMG SRC='foo.gif' ALT='$title'></H1>
> "; ?>
> ------
> This fails, producing only "Doesn" in whatever format corresponds to
> H1. I'm guessing that's because the singlequote in the variable
> is somehow interacting with the singlequotes in the echoed string.
>
> However, if I try this:
> ======
> <?php echo '
> <H1><IMG SRC="_images/_rock/Zacs World.gif" ALT="$title"></H1>
> '; ?>
> ------
> (which I perhaps prefer,
> because the HTML looks the way I would like it to look)
> this also fails, producing "$title" in whatever format corresponds to
> H1.
>
> Is there some way I can "escape" or "quote" the singlequote in the
> variable so that it will just be taken as a value (I guess)
> rather than as something to be concatenated with what's around it
> and thus interacting with the quotes around it?
>
> I've tried doubling it and prefacing it with backslash,
> but that just displays (if at all) as the same thing
> only with an extra quote or with a backslash.
>
>
> ---
> avast! Antivirus: Inbound message clean.
> Virus Database (VPS): 071206-0, 06/12/2007
> Tested on: 07/12/2007 12:58:16
> avast! - copyright (c) 1988-2007 ALWIL Software.
> http://www.avast.com
>
>
>
>

it can get frustrating. But this is what i do to solve this.
note the two type of quotes used single ' and double "

$title = "This'll work";

echo '<h1><IMG SRC="_images/_rock/Zacs World.gif" ALT="' . $title . '">
</h1>';


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 071206-0, 06/12/2007
Tested on: 07/12/2007 13:04:48
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com

[Back to original 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

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