Guest User

Untitled

a guest
Jan 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. $unicodeTable = array('<sup>1</sup>'=>'U+00B9', '<sup>2</sup>'=>'U+00B2', '<sup>3</sup>'=>'U+00B3', '<sup>4</sup>'=>'U+2074', '<sup>5</sup>'=>'U+2075');
  2.  
  3. function replace_unicode_escape_sequence($match) {
  4. return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
  5. }
  6.  
  7. function unicode_chr ($chr) {
  8. $x = explode("+", $chr);
  9. $str = "u".end($x);
  10. return preg_replace_callback('/\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
  11. }
  12.  
  13. foreach($unicodeTable as $uKey=>$uValue){
  14. $text = str_replace($uKey, unicode_chr($uValue), $text);
  15. }
  16.  
  17. x² or xⁿ
  18.  
  19. json_decode('"u00B3"') // for PHP 5.x
  20.  
  21. "u{00B2}" // for PHP 7.x
Add Comment
Please, Sign In to add comment