Advertisement
blistovmhz

Untitled

Oct 3rd, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. <?php
  2. //decode decimal HTML entities added by web browser
  3. $body = preg_replace('/&#\d{2,5};/ue', "utf8_entity_decode('$0')", $body );
  4. //decode hex HTML entities added by web browser
  5. $body = preg_replace('/&#x([a-fA-F0-7]{2,8});/ue', "utf8_entity_decode('&#'.hexdec('$1').';')", $body );
  6.  
  7. //callback function for the regex
  8. function utf8_entity_decode($entity){
  9. $convmap = array(0x0, 0x10000, 0, 0xfffff);
  10. return mb_decode_numericentity($entity, $convmap, 'UTF-8');
  11. }
  12. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement