Description
The following code:
<?php
var_dump(mb_strrpos("\xA9\xA9X", "\xA9", -2, "ISO-8859-1"));
var_dump(strrpos("\xA9\xA9X", "\xA9", -2));
Resulted in this output:
But I expected this output instead:
For a single-byte encoding one byte is one character, so mb_strrpos() should agree with strrpos() here. The result is wrong for a negative offset in any non-UTF-8 encoding. An ISO-8859-1 needle byte in 0x80-0xBF gives a position that is too early, and an ASCII needle in UTF-16 also returns the wrong position.
PHP Version
PHP 8.4.25-dev (the same code is in 8.3, 8.5 and master)
Operating System
macOS 27.0
Description
The following code:
Resulted in this output:
But I expected this output instead:
For a single-byte encoding one byte is one character, so
mb_strrpos()should agree withstrrpos()here. The result is wrong for a negative offset in any non-UTF-8 encoding. An ISO-8859-1 needle byte in 0x80-0xBF gives a position that is too early, and an ASCII needle in UTF-16 also returns the wrong position.PHP Version
PHP 8.4.25-dev (the same code is in 8.3, 8.5 and master)
Operating System
macOS 27.0