473,224 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Backslash-apostrophe POOF.

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
4 2250

"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Aloysio Figueiredo | last post by:
I need to replace every ocurrence of '/' in s by '\/' in order to create a file named s. My first attempt was: s = '\/'.join(s.split('/')) but it doesn't work: >>> s = 'a/b' >>> s =...
3
by: Sathyaish | last post by:
In trying to replace character literals for their char constant, I am having difficulty printing the char constant for backslash. It instead prints the char literal. How do I resovle this? ...
6
by: John Salerno | last post by:
I have this: subdomain = raw_input('Enter subdomain name: ') path = r'C:\Documents and Settings\John Salerno\My Documents\My Webs\1and1\johnjsalerno.com\' + subdomain Obviously the single...
2
by: John Dann | last post by:
I guess there must be some convention or Windows specification for whether the backslash immediately preceding the file name in a full path string to a file is formally part of the path string or...
5
by: shalini jain | last post by:
Hi, I want to know how to use split function to split the string based on backslash(\). Actually backslash is appearing at the end of the string. and i want to remove it. so if anyone could guide...
5
by: Yansky | last post by:
Hi, I'm trying to write a backslash as a text node into the style tag of a web page, but IE is not letting me(perhaps because of security or something?). I need to write a backslash because it is...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
2
by: Tobiah | last post by:
>>"'" "'" "'" "\\'" "\\'" This is quite different than any other language that I am used to. Normally, a double backslash takes away the special meaning of the last backslash, and so you...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
4
nithinpes
by: nithinpes | last post by:
I will boil down my exact requirement to this: I should print out lines that do not contain semi-colon, backslash and closing parentheses. The following one -liner works fine. perl -ne "unless(//)...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.