Why does var_dump (strpos ("mrwagon",626)); output int (1)
Why does var_dump (strpos ("mrwagon",626)); output int (1)
look at the core C code implementation of this function:
if (Z_TYPE_P(needle) == IS_STRING) {
if (!Z_STRLEN_P(needle)) {
php_error_docref(NULL, E_WARNING, "Empty needle");
RETURN_FALSE;
}
found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset,
Z_STRVAL_P(needle),
Z_STRLEN_P(needle),
ZSTR_VAL(haystack) + ZSTR_LEN(haystack));
} else {
//char
if (php_needle_char(needle, needle_char) != SUCCESS) {
RETURN_FALSE;
}
needle_char[1] = 0;
php_error_docref(NULL, E_DEPRECATED,
"Non-string needles will be interpreted as strings in the future. " \
"Use an explicit chr() call to preserve the current behavior");
//char
found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset,
needle_char,
1,
ZSTR_VAL(haystack) + ZSTR_LEN(haystack));
}
static int php_needle_char(zval *needle, char *target)
{
switch (Z_TYPE_P(needle)) {
case IS_LONG:
//long
*target = (char)Z_LVAL_P(needle);
return SUCCESS;
case IS_NULL:
case IS_FALSE:
*target = '\0';
return SUCCESS;
case IS_TRUE:
*target = '\1';
return SUCCESS;
case IS_DOUBLE:
*target = (char)(int)Z_DVAL_P(needle);
return SUCCESS;
case IS_OBJECT:
*target = (char) zval_get_long(needle);
return SUCCESS;
default:
php_error_docref(NULL, E_WARNING, "needle is not a string or an integer");
return FAILURE;
}
}
if the needle
parameter provided by you is not a string, the php_needle_char
method will be called to convert to the string corresponding to the parameter. In the question, the ASCII letter corresponding to 626 is r
.
you can also use chr
to see if the output is r
.
C source code: https://github.com/php/php-sr.
There is no such value in ASCII, so why does the chr
method convert 626 to r
? Take a look at how the C code is implemented:
int zend_compile_func_chr(znode *result, zend_ast_list *args) /* {{{ */
{
if (args->children == 1 &&
args->child[0]->kind == ZEND_AST_ZVAL &&
Z_TYPE_P(zend_ast_get_zval(args->child[0])) == IS_LONG) {
// 0xff 0xff255.
zend_long c = Z_LVAL_P(zend_ast_get_zval(args->child[0])) & 0xff;
result->op_type = IS_CONST;
ZVAL_INTERNED_STR(&result->u.constant, ZSTR_CHAR(c));
return SUCCESS;
} else {
return FAILURE;
}
}
any number, calculated with 0xff, the result will not be greater than 255, which is within the range of ASCII code expression. 626&0xff=114
, which corresponds to r
.
in order to facilitate development, we plan to create a LNMP environment based on docker, which makes it much more convenient to change computers or unify the team s development environment. choreographed a docker-compose.yaml file with nginx, php-fp...
external network access domain name: https: api.baidu.com internal network domain name: http: local.baidu.com this domain name is inaccessible outside the network! It is 127.0.0.1 pointed to by a private network address. I use nginx reverse proxy ...
description: a regular match is given to the content of an input box, and the matching content is the product activation code. looks like this: "0C31-0B81-BB32-3094-0C31-0B81-BB32-3094 " Code: $( -sharplicenseCode ).keyup(function () { le...
I configured the MIME type of the file with the amr suffix in the apache configuration as application ms-download, Why it is a garbled page when opening a file in amr format using window.open in chrome, while a file in amr format can be successfully dow...
what does the code circled in the following picture mean? ...
rewrite rules: RewriteRule (.*) (.*) (.*) index .html index.php?p=$1&c=$2&a=$3 [QSA] access Home Blog blog index.html?page=2 can access index.php?p=Home&c=Blog&c=blog&page=2 normally but when the original link is index.php?p=Home&c=Blog&a...
$selectTip = $pdo->query("SELECT * FROM `tips_rate` WHERE `tip_id` = ".$row[ id ]." " ); $selecttotal = mysqli_num_rows($selectTip); $rate = $pdo->query("SELEC...
the following is the back-end code I think $username= is a randomly generated string in the output, so write $username=$number; like this, but this is an execution error, how to do it? For advice, thank you <?php $username=$_POST[ username ]; $nu...
adopt a reward of 10 yuan, 1045 Access denied for user root @ localhost (using password:NO) recently, when I was at the front end of my self-study, I came into contact with a little bit of database. This happened when I made a new connection on ...
the original domain name of our company s website has expired. I want to change it to another domain name. How can I change it? The website is developed using Aliyun s Yunmeng. ...
post table is the article table, the primary key is id tag table is the tag table, the primary key is id post_tag is the intermediate mapping table, and the field is post_id,tag_id now I want to select tag 1 to find out that all the tags and article...
what happens when you get a list of followers through access_token after getting access_token and show that this operation cannot be performed? $url = "https: api.weixin.qq.com cgi-bin token?grant_type=client_credential&appid=$appid&secre...
In apache,event mode, 8 processes are started. Set to perform 10000 automatic recreations. On the next day, there were only two hundred and three processes. is this the number of processes that apache thinks there are not enough tasks and automaticall...
$first is the data read by the database as shown in figure : read through the database can not change the line, directly written in the code can break the line, solve =! ...
as shown in the figure, the generated url does not have a domain name. Where do I need to configure it? ...
there is an h5 page embedded in the encapsulated APP. After the function of issuing an order, how can I get the user s id to add the address and place the order ...
1. Background of the problem: recently, it has been almost exclusively said on php7, that only php7 compiled with GCC 4.8 will open Global Register for opline and execute_data . 2. Question description: Q: what is 1Global Register for opline and e...
the query data is printed to see that _ id is objectID,. If it is directly converted to json,_id, it will be empty. Can you change objectID to string, and then to json? ...
$result= array(); foreach ($infos as $key => $info) { $result[$info[ time ]][] = $info;}; $results=array_slice($result,0,255); in this code, I want to use array_slice to remove the key value of $result, but I don t use . ...
stateful fields are often saved in the database, which are represented by numbers: 0-> fail reject 1-> success pass and so on, I want to convert 0 or 1 into Chinese characters in the obtained results, is there any good way to quickly complete t...