I have js code:
var b = "aHR0cDovL3d3dy5oZHpvZy5jb20vZ2V0X2ZpbGUvМS84Y2Е5МTЕ4ZmМyNmVkNTk0ZmI5Yzc2ZWI2Y2Y2YWVmМС85NDАwМС85NDU4Ny85NDU4Ny5tcDQvP3RpbWU9МjАxNzА5МjYyМDIxNDYmcz05МTUzZmNmYjАyOTUyOWQxY2JhZTВkYzNkY2ZhODVmZiZicj0xODЕ1JmQ9МTcwNyZmPXZpZGVvLm0zdTg~";
var f = "\u0410\u0412\u0421D\u0415FGHIJKL\u041cNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,~".indexOf(b.charAt(0));
document.write(f);
It return 26. And I convert js code to php code:
$url = 'aHR0cDovL3d3dy5oZHpvZy5jb20vZ2V0X2ZpbGUvМS84Y2Е5МTЕ4ZmМyNmVkNTk0ZmI5Yzc2ZWI2Y2Y2YWVmМС85NDАwМС85NDU4Ny85NDU4Ny5tcDQvP3RpbWU9МjАxNzА5МjYyМDIxNDYmcz05МTUzZmNmYjАyOTUyOWQxY2JhZTВkYzNkY2ZhODVmZiZicj0xODЕ1JmQ9МTcwNyZmPXZpZGVvLm0zdTg~';
$str = "\u0410\u0412\u0421D\u0415FGHIJKL\u041cNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,~";
$str = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, $str);
$f = strpos($str, $url[0]);
echo $f;
But it return 31. Why?
'\u0421' in JavaScript is representative of a character. In Php however, it is not. That's why JavaScript is showing fewer spaces between index 0 and the first instance of 'a'.
To remedy this... I'm pretty sure this is what you're looking for... How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?
来源:https://stackoverflow.com/questions/46439056/how-to-convert-javascript-code-to-its-php-equivalent