Thingy Ma Jig is the blog of Nicholas Thompson and contains any useful tips, sites and general blog-stuff which are considered interesting or handy!
Posted on 07 February 2011 in
code
programming
Ever needed to Entity Encode a block of text (maybe to partially protect it from spam bots or just hide/obfuscate the content?). I did. It’s pretty easy.
If it’s just basic Entity Encoding, you can always use htmlentities
- however this only does the “important” characters such as quotes, ampersands and angle brackets.
If you want to entity encode ALL characters from a string, try this:
$phone_number = mb_encode_numericentity('0123 456789', array(0x00, 0xff, 0, 0xffff), 'UTF-8');
That produces:
0123 456789
This is pretty useful if you want to hide a phone number from things like the Skype auto-highlighter.