Reputation: 17
I am working on some PHP code to identify HEX character codes in a string and convert them to their "as seen on screen" equivalent. Mainly, there HEX codes are for accented characters like é, ç and so on.
For example, I am receiving a string like this:
$str = "cafés"; - NOTE there is a semicolon after the 9 (i had to remove it to stop this text editor converting it!
The HEX part of the string is é (again with semicolon at end) - and I am needing to convert that to its "as seen on screen" equivalent, in this case "é". So the converted string would be "cafés".
The following PHP code works, but I have to write one for each HEX code, and there are scores of them.
$keywords = str_replace("é","é",$keywords); [again the needle part has a semicolon]
Can anyone suggest an existing PHP function that can scan any string for known HEX codes and convert it to the display equivalent?
I am working in UTF8 otherwise.
Thanks for your consideration, sorry if my terminology sounds amateur.
James
Upvotes: 0
Views: 1180
Reputation: 5503
http://www.php.net/manual/en/function.html-entity-decode.php
This will convert HTML entities into their associated char
$keywords = html_entity_decode($keywords);
Upvotes: 2