Backslash-apostrophe POOF.

R

Razzbar

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?
 
R

Razzbar

"Razzbar" <[email protected]> wrote 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.
 
R

Razzbar

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.
 
T

Thomas 'PointedEars' Lahn

Razzbar said:
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.php> and
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top