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

$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?

No-one?

I don’t think the ' is a standard entity that can be decoded.

But I think it’s apostrophe. How can I translate that one then?

’ 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.

Off Topic:

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—

[noparse]'[/noparse]

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.

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?

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.

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(''', [COLOR="#FF0000"]ENT_QUOTES[/COLOR] | ENT_HTML401);