Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getUTF16CodeUnits($string) {
- $string = substr(json_encode($string), 1, -1);
- preg_match_all("/\\\\u[0-9a-fA-F]{4}|./mi", $string, $matches);
- return $matches[0];
- }
- function JS_charCodeAt($utf16CodeUnitsArray, $index) {
- $unit = $utf16CodeUnitsArray[$index];
- if(strlen($unit) > 1) {
- $hex = substr($unit, 2);
- return hexdec($hex);
- }
- else {
- return ord($unit);
- }
- }
- $str = "tππΏππβοΈππ¨π¬π―¦";
- $str = str_repeat($str, 250); //repeat $str 250 times
- $utf16CodeUnits = getUTF16CodeUnits($str);
- echo "Length is: ".count($utf16CodeUnits)."\n";
- for($i=0; $i<count($utf16CodeUnits); $i++) {
- echo "charCodeAt(".$i."): ".JS_charCodeAt($utf16CodeUnits, $i)."\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement