By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Backslash-apostrophe POOF.

P: n/a
I'm working on a bookmarklet that grabs information from a page and
submits it to a server. Yet another social bookmarking application.
I'm having trouble with page titles that include an apostrophe.

I'm using encodeURIComponent() around the page title, and again around
the URL. Apparently the browser is inserting a backslash before any
apostrophe. I can see that when I write the $_GET data to a file in
PHP on the server. When the GET data is processed, PHP generates a
page with a form, and the data is plugged into some input fields. The
page is sent to the user's browser for editing and approval, and
there's where the problem shows up. Here's the transformation...

Say we have a page with the title "Here's the page" (minus the
outer quotes)

Page title: -- Here's the page // the title gets
encodeURIComponent
PHP gets -- Here\'s the page // a backslash gets
inserted somehow.
HTML form -- Here\ // truncated!

I don't know why this is happening, or what to do about it. I tried
using PHP stripslashes() and that doesn't do it. What do I need to
do?
Jul 26 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Razzbar" <gl***@potatoradio.f2s.comwrote in message
news:15**********************************@s21g2000 prm.googlegroups.com...
I'm working on a bookmarklet that grabs information from a page and
submits it to a server. Yet another social bookmarking application.
I'm having trouble with page titles that include an apostrophe.

I'm using encodeURIComponent() around the page title, and again around
the URL. Apparently the browser is inserting a backslash before any
apostrophe. I can see that when I write the $_GET data to a file in
PHP on the server. When the GET data is processed, PHP generates a
page with a form, and the data is plugged into some input fields. The
page is sent to the user's browser for editing and approval, and
there's where the problem shows up. Here's the transformation...

Say we have a page with the title "Here's the page" (minus the
outer quotes)

Page title: -- Here's the page // the title gets
encodeURIComponent
PHP gets -- Here\'s the page // a backslash gets
inserted somehow.
HTML form -- Here\ // truncated!
What does "view source" show for the HTML form ?

Tim
>
I don't know why this is happening, or what to do about it. I tried
using PHP stripslashes() and that doesn't do it. What do I need to
do?

Jul 26 '08 #2

P: n/a
On Jul 25, 8:31 pm, "Tim Williams" <timjwilliams at gmail dot com>
wrote:
"Razzbar" <gl...@potatoradio.f2s.comwrote in message
What does "view source" show for the HTML form ?
AH! The form is getting what PHP sees, i.e. a backslash before the
apostrophe. I've coded the HTML form with single quotes around the
value, and apparently the browser is not interpreting the backslash
correctly. I expect a backslash to mean "ignore the meaning of the
following special character", but it's not doing that. The apostrophe
is marking the end of the form input value. Shucks, view source even
highlighted the text after the apostrophe up to the intended ending
single quote.

Sooooo.... I just this minute recoded the HTML, replacing the single-
quotes with double-quotes, and guess what happened. Now the form shows
what PHP sees, i.e. the whole title, complete with a backslash and an
apostrophe.

How did that backslash get in there, and how can I get rid of it? And
sorry for posting in the wrong newsgroup. I think this is a PHP issue,
not Javascript. It's both, really. I should have crossposted.

Thanks, it sorta helped even if it didn't solve it.
Jul 26 '08 #3

P: n/a
The problem was solved by changing this,

<input value = '<? echo $value ?>'>

to,

<input value = "<? echo stripslashes($value) ?>">

How that backslash got there remains a mystery.
Jul 26 '08 #4

P: n/a
Razzbar wrote:
The problem was solved by changing this,

<input value = '<? echo $value ?>'>

to,

<input value = "<? echo stripslashes($value) ?>">
Should be either

<input value="<?= htmlentities(stripslashes($value)); ?>">

or

<input value="<?php echo htmlentities(stripslashes($value)); ?>">

See <http://php.net/htmlentities>, and
<http://php.net/manual/en/ini.core.phpand
<http://bugs.php.net/bug.php?id=16838>.
How that backslash got there remains a mystery.
Perhaps an extra addslashes() or
<http://php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc>.
X-Post & F'up2 comp.lang.php

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Jul 26 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.