Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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');
- function replace_unicode_escape_sequence($match) {
- return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
- }
- function unicode_chr ($chr) {
- $x = explode("+", $chr);
- $str = "u".end($x);
- return preg_replace_callback('/\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
- }
- foreach($unicodeTable as $uKey=>$uValue){
- $text = str_replace($uKey, unicode_chr($uValue), $text);
- }
- x² or xⁿ
- json_decode('"u00B3"') // for PHP 5.x
- "u{00B2}" // for PHP 7.x
Add Comment
Please, Sign In to add comment