brad62 — 2013-10-10T12:18:46-04:00 — #1
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
$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?
brad62 — 2013-10-11T03:11:11-04:00 — #2
michael_morris1 — 2013-10-11T16:18:43-04:00 — #3
I don't think the ' is a standard entity that can be decoded.
brad62 — 2013-10-11T17:11:03-04:00 — #4
But I think it's apostrophe. How can I translate that one then?
chris_upjohn — 2013-10-11T21:03:39-04:00 — #5
' isn't a standard ASCII character so it can't be decoded by conventional functions, you could do something simple like the following.
$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.
ralphm — 2013-10-11T21:11:27-04:00 — #6
If you use the basic [noparse]
[/noparse] 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—
brad62 — 2013-10-12T04:36:35-04:00 — #7
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.
brad62 — 2013-10-14T05:19:28-04:00 — #8
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?
chris_upjohn — 2013-10-14T21:00:38-04:00 — #9
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.
jeff_mott — 2013-11-05T12:59:29-05:00 — #10
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.
$thisWillWork = html_entity_decode(''', <font color='"#FF0000"'>ENT_QUOTES</font> | ENT_HTML401);