Backslash-apostrophe POOF.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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
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

Re: Backslash-apostrophe POOF.


Razzbar schrieb:
Quoted text here. Click to load it

Are maybe there *two* times \?
So encodeURIComponent make that:   Here\'s
And magic qutoes makes that: Here\\'

I use this construct:
$bd = urlencode($_REQUEST['m_body']);
$bd = get_magic_quotes_gpc() ? $bd : urlencode($bd);

Re: Backslash-apostrophe POOF.

Razzbar wrote:
Quoted text here. Click to load it

What do you see when you look at the page source?

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Backslash-apostrophe POOF.

Razzbar contained the following:

Quoted text here. Click to load it


htmlentities(stripslashes($var), ENT_QUOTES);

Geoff Berrow  0110001001101100010000000110

Re: Backslash-apostrophe POOF.

Quoted text here. Click to load it
It's trickier than that! Simply using stripslashes() solved the
backslash+apostrophe issue, but then I tried it on a page title with
some HTML entities in it, and once again, there was a truncation at
the first '<' character. So... using your code solved that one. Until
I had a title that was in Japanese, which gave no problem until I
started fixing this. That one renders the UTF codes, not the
characters as before.


Site Timeline