473,382 Members | 1,225 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,382 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 2257

"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
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.