TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > PHP

Notices

single quote in string constant

PHP


Reply
 
Thread Tools Display Modes
Old 03-12-2007, 11:19 AM   #11
macca
Guest
 
Posts: n/a
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
Old 03-12-2007, 01:58 PM   #12
Onideus Mad Hatter
Guest
 
Posts: n/a
Re: single quote in string constant

On Sun, 02 Dec 2007 19:16:06 -0500, Jerry Stuckle
<> 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 ¹




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 ***** 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 **** 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 ****ing 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
Old 07-12-2007, 06:57 PM   #13
Steve
Guest
 
Posts: n/a
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.
>
>
>
>
>


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.




  Reply With Quote
Old 07-12-2007, 09:00 PM   #14
Michael Fesser
Guest
 
Posts: n/a
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
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 07:35 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional