single quote in string constant

This is a discussion on single quote in string constant within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I know there are a million ways to skin a cat, but you could use htmlentities(). <?php echo "&...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 12-03-2007
macca
 
Posts: n/a
Default Re: single quote in string constant

I know there are a million ways to skin a cat, but you could use
htmlentities().



<?php echo "<H1><IMG SRC='foo.gif'
ALT='".htmlentities($title,ENT_QUOTES)."'></H1>"; ?>


reagrds,

paul
Reply With Quote
  #12 (permalink)  
Old 12-03-2007
Onideus Mad Hatter
 
Posts: n/a
Default Re: single quote in string constant

On Sun, 02 Dec 2007 19:16:06 -0500, Jerry Stuckle
<jstucklex@attglobal.net> wrote:

>MangroveRoot wrote:
>> MangroveRoot wrote:
>>> At the very top of my .php file, I define a variable as follows:
>>> ======
>>> $title = "Doesn't Matter";
>>> ------
>> > (. . .)
>>> 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?
>> > (. . .)

>>
>> BTW, which of these groups --
>> alt.comp.lang.php, alt.php, comp.lang.php --
>> is the correct one for questions of this sort?
>>

>
>None of them. This is an HTML problem.


Ignore Jerry, he's the resident doofus around here. He likes to
pretend he knows how to code but he doesn't actually have any work in
the area. Either group is fine to ask yer question in.

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
http://www.backwater-productions.net/hatter-blog


Hatter Quotes
-------------
"You're only one of the best if you're striving to become one of the
best."

"I didn't make reality, Sunshine, I just verbally bitch slapped you
with it."

"I'm not a professional, I'm an artist."

"Your Usenet blinders are my best friend."

"Usenet Filters - Learn to shut yourself the fuck up!"

"Drugs killed Jesus you know...oh wait, no, that was the Jews, my
bad."

"There are clingy things in the grass...burrs 'n such...mmmm..."

"The more I learn the more I'm killing my idols."

"Is it wrong to incur and then use the hate ridden, vengeful stupidity
of complete strangers in random Usenet froups to further my art?"

"Freedom is only a concept, like race it's merely a social construct
that doesn't really exist outside of your ability to convince others
of its relevancy."

"Next time slow up a lil, then maybe you won't jump the gun and start
creamin yer panties before it's time to pop the champagne proper."

"Reality is directly proportionate to how creative you are."

"People are pretty fucking high on themselves if they think that
they're just born with a soul. *snicker*...yeah, like they're just
givin em out for free."

"Quible, quible said the Hare. Quite a lot of quibling...everywhere.
So the Hare took a long stare and decided at best, to leave the rest,
to their merry little mess."

"There's a difference between 'bad' and 'so earth shatteringly
horrible it makes the angels scream in terror as they violently rip
their heads off, their blood spraying into the faces of a thousand
sweet innocent horrified children, who will forever have the terrible
images burned into their tiny little minds'."

"How sad that you're such a poor judge of style that you can't even
properly gauge the artistic worth of your own efforts."

"Those who record history are those who control history."

"I am the living embodiment of hell itself in all its tormentive rage,
endless suffering, unfathomable pain and unending horror...but you
don't get sent to me...I come for you."

"Ideally in a fight I'd want a BGM-109A with a W80 250 kiloton
tactical thermonuclear fusion based war head."

"Tell me, would you describe yourself more as a process or a
function?"

"Apparently this group has got the market cornered on stupid.
Intelligence is down 137 points across the board and the forecast
indicates an increase in Webtv users."

"Is my .sig delimiter broken? Really? You're sure? Awww,
gee...that's too bad...for YOU!" `, )
Reply With Quote
  #13 (permalink)  
Old 12-07-2007
Steve
 
Posts: n/a
Default Re: single quote in string constant

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



Reply With Quote
  #14 (permalink)  
Old 12-07-2007
Michael Fesser
 
Posts: n/a
Default Re: single quote in string constant

..oO(Steve)

>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";


$title .= ', but not on my 19" screen.';

SCNR

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


The correct solution (htmlspecialchars()) was posted already.

Micha
Reply With Quote
  #15 (permalink)  
Old 12-08-2007
Onideus Mad Hatter
 
Posts: n/a
Default Re: single quote in string constant

On Fri, 07 Dec 2007 15:47:01 +0100, Michael Fesser <netizen@gmx.de>
wrote:

>.oO(Steve)
>
>>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";

>
>$title .= ', but not on my 19" screen.';
>
>SCNR
>
>>echo '<h1><IMG SRC="_images/_rock/Zacs World.gif" ALT="' . $title . '">
>></h1>';

>
>The correct solution (htmlspecialchars()) was posted already.


There isn't really a "correct" solution. There are a variety of ways
to do it, some more or less efficient than others (although ultimately
negligible). The only thing that really matters is...what works best
for you. Find that method, then use it.

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
http://www.backwater-productions.net/hatter-blog


Hatter Quotes
-------------
"You're only one of the best if you're striving to become one of the
best."

"I didn't make reality, Sunshine, I just verbally bitch slapped you
with it."

"I'm not a professional, I'm an artist."

"Your Usenet blinders are my best friend."

"Usenet Filters - Learn to shut yourself the fuck up!"

"Drugs killed Jesus you know...oh wait, no, that was the Jews, my
bad."

"There are clingy things in the grass...burrs 'n such...mmmm..."

"The more I learn the more I'm killing my idols."

"Is it wrong to incur and then use the hate ridden, vengeful stupidity
of complete strangers in random Usenet froups to further my art?"

"Freedom is only a concept, like race it's merely a social construct
that doesn't really exist outside of your ability to convince others
of its relevancy."

"Next time slow up a lil, then maybe you won't jump the gun and start
creamin yer panties before it's time to pop the champagne proper."

"Reality is directly proportionate to how creative you are."

"People are pretty fucking high on themselves if they think that
they're just born with a soul. *snicker*...yeah, like they're just
givin em out for free."

"Quible, quible said the Hare. Quite a lot of quibling...everywhere.
So the Hare took a long stare and decided at best, to leave the rest,
to their merry little mess."

"There's a difference between 'bad' and 'so earth shatteringly
horrible it makes the angels scream in terror as they violently rip
their heads off, their blood spraying into the faces of a thousand
sweet innocent horrified children, who will forever have the terrible
images burned into their tiny little minds'."

"How sad that you're such a poor judge of style that you can't even
properly gauge the artistic worth of your own efforts."

"Those who record history are those who control history."

"I am the living embodiment of hell itself in all its tormentive rage,
endless suffering, unfathomable pain and unending horror...but you
don't get sent to me...I come for you."

"Ideally in a fight I'd want a BGM-109A with a W80 250 kiloton
tactical thermonuclear fusion based war head."

"Tell me, would you describe yourself more as a process or a
function?"

"Apparently this group has got the market cornered on stupid.
Intelligence is down 137 points across the board and the forecast
indicates an increase in Webtv users."

"Is my .sig delimiter broken? Really? You're sure? Awww,
gee...that's too bad...for YOU!" `, )
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:48 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0