'Convert all characters to dec or hex HTML code equivalent
Is there a way I can convert ALL characters, including regular ones, using PHP to something like this:
&\#38; &\#233; &\#224; &\#231; &\#60;
When I say regular characters I mean to say chars like "ABCD123!@#$", etc.
Is this possible?
Solution 1:[1]
There are several ways. One is
join('', array_map(create_function('$c', 'return "&#".ord($c).";";'), str_split($string)));
Solution 2:[2]
Piggy-backing on Alex's/Anomie's answer, to get full Unicode support, you could use the package at http://hsivonen.iki.fi/php-utf8/ to do:
'&#' . join(';&#', utf8ToUnicode($str) . ';'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anomie |
| Solution 2 | Brett Zamir |
