mirror of
https://github.com/php/php-src.git
synced 2025-08-18 06:58:55 +02:00
Restore ability to use strrpos/strripos with an ordinal needle
This commit is contained in:
parent
86c8a87283
commit
3d6fcddfd2
1 changed files with 28 additions and 4 deletions
|
@ -1570,14 +1570,26 @@ PHP_FUNCTION(stripos)
|
|||
Finds position of last occurrence of a string within another string */
|
||||
PHP_FUNCTION(strrpos)
|
||||
{
|
||||
zval *zneedle;
|
||||
char *needle, *haystack;
|
||||
int needle_len, haystack_len, offset = 0;
|
||||
char *p, *e;
|
||||
char *p, *e, ord_needle[2];
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &haystack, &haystack_len, &needle, &needle_len, &offset) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &zneedle, &offset) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (Z_TYPE_P(zneedle) == IS_STRING) {
|
||||
needle = Z_STRVAL_P(zneedle);
|
||||
needle_len = Z_STRLEN_P(zneedle);
|
||||
} else {
|
||||
convert_to_long(zneedle);
|
||||
ord_needle[0] = (char)(Z_LVAL_P(zneedle) & 0xFF);
|
||||
ord_needle[1] = '\0';
|
||||
needle = ord_needle;
|
||||
needle_len = 1;
|
||||
}
|
||||
|
||||
if ((haystack_len == 0) || (needle_len == 0)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
@ -1609,15 +1621,27 @@ PHP_FUNCTION(strrpos)
|
|||
Finds position of last occurrence of a string within another string */
|
||||
PHP_FUNCTION(strripos)
|
||||
{
|
||||
zval *zneedle;
|
||||
char *needle, *haystack;
|
||||
int needle_len, haystack_len, offset = 0;
|
||||
char *p, *e;
|
||||
char *p, *e, ord_needle[2];
|
||||
char *needle_dup, *haystack_dup;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &haystack, &haystack_len, &needle, &needle_len, &offset) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &zneedle, &offset) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (Z_TYPE_P(zneedle) == IS_STRING) {
|
||||
needle = Z_STRVAL_P(zneedle);
|
||||
needle_len = Z_STRLEN_P(zneedle);
|
||||
} else {
|
||||
convert_to_long(zneedle);
|
||||
ord_needle[0] = (char)(Z_LVAL_P(zneedle) & 0xFF);
|
||||
ord_needle[1] = '\0';
|
||||
needle = ord_needle;
|
||||
needle_len = 1;
|
||||
}
|
||||
|
||||
if ((haystack_len == 0) || (needle_len == 0)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue