SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    html_entity_decode problem

    I have a mail thing that is sending out e-mails.
    In the subject I had some problem with characters sometimes and I thought I solved it.
    It looks fine when I try it in my webmail, but when I saw the subject in my iPhone it looked weird.

    In the webmail it looks like this: It's here now
    But in the iPhone it looks like this: It's here now

    In my code I solved it with the following code
    PHP Code:
    $subject html_entity_decode($subject); 
    But it doesn't seem to solve it for the phone. I have also discovered that it looks weird in some e-mails that are being returned.
    How should I do this to make it work?

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No-one?

  3. #3
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,023
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    I don't think the ' is a standard entity that can be decoded.

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But I think it's apostrophe. How can I translate that one then?

  5. #5
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    ' isn't a standard ASCII character so it can't be decoded by conventional functions, you could do something simple like the following.

    PHP Code:
    $subject str_replace('&\#39;''\''html_entity_decode($subject)); 
    Make sure you remove the backslash in there as it's only there to stop it from rendering.

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,120
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Off Topic:

    Quote Originally Posted by chris.upjohn View Post
    Make sure you remove the backslash in there as it's only there to stop it from rendering.
    If you use the basic [code] [/code] tags, you can highlight part of the character reference with a color so that it's not seen for what it is: ' ... which comes from—

    [COLOR="#FF0000"]&#[/COLOR][COLOR="#FF0000"]39;[/COLOR]
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  7. #7
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So, maybe it's already entered the wrong way in the first place? In the form where I add the text to the db? I use utf-8 in my db.

  8. #8
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What is the best way to check a form field so I input the chars the right way? First I sanitize the inputs. Then I would like chars like ' or " and other that a user might add to be inserted into mysql the right way. What should I use? And what do I need to output these the right way later?

  9. #9
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    There isn't a standard technique for managing this apart from writing your own snippets of code to manage what you need replaced, typically I would look for everything that could be a possible match and replace them with a UTF-8 equivalent character.

  10. #10
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Sorry I found this thread a bit late.

    PHP maybe could be given a pass for not decoding the named entity -- ' -- because that particular named entity is non-standard, but there's no excuse for it not to be able to decode the numeric code. Fortunately, despite this borked default behavior, it's pretty easy to fix with the flags parameter.

    Code:
    $thisWillWork = html_entity_decode(''', ENT_QUOTES | ENT_HTML401);
    "First make it work. Then make it better."


Bookmarks

Posting Permissions

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