Backslash-apostrophe POOF.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Razzbar

    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 encodeURICompon ent() 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
    encodeURICompon ent
    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?
  • Tim Williams

    #2
    Re: Backslash-apostrophe POOF.


    "Razzbar" <glakk@potatora dio.f2s.comwrot e in message
    news:15ba06bf-7213-4963-94d6-930ad59239f0@s2 1g2000prm.googl egroups.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 encodeURICompon ent() 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
    encodeURICompon ent
    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?

    Comment

    • Razzbar

      #3
      Re: Backslash-apostrophe POOF.

      On Jul 25, 8:31 pm, "Tim Williams" <timjwilliams at gmail dot com>
      wrote:
      "Razzbar" <gl...@potatora dio.f2s.comwrot e 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.


      Comment

      • Razzbar

        #4
        Solved: Backslash-apostrophe POOF.

        The problem was solved by changing this,

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

        to,

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

        How that backslash got there remains a mystery.

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Solved: Backslash-apostrophe POOF.

          Razzbar wrote:
          The problem was solved by changing this,
          >
          <input value = '<? echo $value ?>'>
          >
          to,
          >
          <input value = "<? echo stripslashes($v alue) ?>">
          Should be either

          <input value="<?= htmlentities(st ripslashes($val ue)); ?>">

          or

          <input value="<?php echo htmlentities(st ripslashes($val ue)); ?>">

          See <http://php.net/htmlentities>, and
          <http://php.net/manual/en/ini.core.phpand
          <http://bugs.php.net/bug.php?id=1683 8>.
          How that backslash got there remains a mystery.
          Perhaps an extra addslashes() or
          <http://php.net/manual/en/info.configurat ion.php#ini.mag ic-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, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

          Comment

          Working...