Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts

    Parsing issue - unencoded ampersand

    Hi all,

    I apologize in advance because this is going to be a bit vague at first.

    My problem is with validating a page - the trip up is the "unencoded ampersand" - I know how to encode it & amp ; (no spaces) but something odd is happening that is stripping that back to the basic &.

    I am using a php news updater (now defunct PHPNews) to insert the code for a php poll script. I think that this updater is the culprit here...I use other updater/blog types of content management and this does not occur.

    I go into the admin of the updater and change all instances of & to & amp ; (no spaces) - when I post it the encoding gets stripped and only the & is left. When I return to the edit screen of the updater I see that that is indeed the case - & amp ; (no spaces) has become & again.

    What could be going on with the updater script - and could this be modified to leave the text as is? I'm sorry I don't know what kind of file or code bit you would need but will be happy to include it here for reference.

    Thank you so much for any advice on this.

    Daf

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Do you have any real issue with this apart from the display in your editor, like errors from validator?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts
    Hi abduraooft,

    Yes - that is what is prompting me to try to resolve this. Because the ampersands are not remaining encoded I am getting the following validation errors:

    Line 1082, Column 130: general entity "pollid" not defined and no default entity

    …bb.com/poll43/poll.swf?setWIDTH=160&pollid=486&owner=phpjabbers.com&phpURL=ht


    This is usually a cascading error caused by a an undefined entity reference or use of an unencoded ampersand (&) in an URL or body text. See the previous message for further details.
    Like I said - I have tried repeatedly to encode the ampersands but as soon as I hit "post" the updater strips 'em ;/

    Thanks!

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Sounds like your 'updater' is crap. Try the numeric entity, & #38 ;, instead of & amp ;, and see if it's stripping that too. What is generating that validation error, btw?
    Last edited by MattF; 01-13-2010 at 04:35 PM.

  • Users who have thanked MattF for this post:

    Daf (01-16-2010)

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    If you have access to the code where it echoes the contents to the page, you could add a function htmlentities() there.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Daf (01-16-2010)

  • #6
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts
    Hi Matt,

    I just tried & #38 ; (no spaces) and it does the same thing.

    I know the updater is really not up to speed on quite a few things and we will be moving to another in the future.

    I was just wondering if there was something that could be added or removed in the posting code that would allow for the encoding.

    Not sure if this is what you need but I'm posting the "post.php" file here. Maybe you will see something - or I can post another file if needed.

    Thanks!!!
    Attached Files Attached Files

  • #7
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by abduraooft View Post
    If you have access to the code where it echoes the contents to the page, you could add a function htmlentities() there.
    Okay - I will see what I can do with that. Thanks!

  • #8
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts
    Okay - partial succcess!

    I found, in the ListingFunctions.php file this bit:

    Code:
    echo $Contents;
    and replaced with:

    Code:
    echo htmlentities($Contents);
    I then went back in and edited the post with the ampersands - replacing with

    & #38 ; (no spaces)

    And it worked!!

    But... when I opened the post for edit, then reposted (which I will have to do daily) it stripped them again.

    Do you think there may be a place in the admin section (edit box) that could use the htmlentities() as well?

    Thanks so much - I'm glad to both get a little progress and learn a bit at the same time!

  • #9
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts
    Update- I didn't check the other ouput areas - apparently this caused all the associated html to display along with the news... oh well.

  • #10
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Instead of htmlentities try using this:

    Code:
    echo str_replace("&","&",$Contents);
    It's a blunt tool rather than a precision instrument but it should do the trick well enough.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    Daf (01-16-2010)

  • #11
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    If htmlenetites didn't do it then this will do just the same, since both will have identical changes to the ampersand to begin with
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #12
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Yes, but the OP said that it worked in one location but displayed ALL associated HTML. This would just patch up the "&" characters. This at least gets us back to the "partial success" stage. Now the OP would just need to find the other spot that is causing issues.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #13
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts
    Hi Rowsdower!

    That did in fact fix both the encoding and visible html - thanks!

    But the problem of it transposing back to simple "&" with each edit remains.

    Bummer, but that's okay. We will just bide our time until I get the new updater in place.

    Thanks to all for the replies!

    Daf


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •