0

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?

justcntt
  • 197
  • 1
  • 2
  • 12
  • look at http://php.net/manual/en/function.chr.php to replace `String.fromCharCode` – Isaac Sep 27 '17 at 03:37
  • Welcome to StackOverflow! Have you tried anything so far? StackOverflow isn't a free code-writing service, and expects you to [try to solve your own problem first](http://meta.stackoverflow.com/questions/261592). Please update your question to show what you have already tried, showing the specific problem you are facing in a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve). For further information, please see [how to ask a good question](http://stackoverflow.com/help/how-to-ask), and take the [tour of the site](http://stackoverflow.com/tour) – Jaromanda X Sep 27 '17 at 03:37
  • can you please tell which function you struggling find alternate in php ? – nithinTa Sep 27 '17 at 03:53
  • It use to decode string – justcntt Sep 27 '17 at 04:09
  • @JaromandaX ok, I know. – justcntt Sep 27 '17 at 04:10
  • Please help me! – justcntt Sep 27 '17 at 04:40

1 Answers1

0

'\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?

jscul
  • 748
  • 1
  • 10
  • 25