1 php_function (Strpos)2 {3Zval *needle;4Zend_string *haystack;5 Char*found =NULL;6 Charneedle_char[2];7Zend_long offset =0;//Search location Default 08 9Zend_parse_parameters_start (2,3)Ten z_param_str (haystack) One z_param_zval (needle) A z_param_optional - Z_param_long (offset) - zend_parse_parameters_end (); the - /*if the search start location is offset<0, convert*/ - if(Offset <0) { -Offset + =(Zend_long) Zstr_len (haystack); + } - /*if offset<0 or offset is greater than (the length of the string to look for) after the conversion, there is no such position in the string to be found*/ + if(Offset <0|| (size_t) offset >Zstr_len (haystack)) { APhp_error_docref (NULL, e_warning,"Offset not contained in string"); at Return_false; - } - - /*Search*/ - if(z_type_p (needle) = = is_string) {//needle is a string - /*needle length is 0, then error*/ in if(!z_strlen_p (needle)) { -Php_error_docref (NULL, e_warning,"Empty Needle"); to Return_false; + } - /*a specific search implementation*/ theFound = (Char*) Php_memnstr (Zstr_val (haystack) +Offset, * z_strval_p (needle), $ z_strlen_p (needle),Panax NotoginsengZstr_val (haystack) +Zstr_len (haystack)); -}Else { the if(Php_needle_char (needle, needle_char)! =SUCCESS) { + Return_false; A } theneedle_char[1] =0; + -Found = (Char*) Php_memnstr (Zstr_val (haystack) +Offset, $ Needle_char, $ 1, -Zstr_val (haystack) +Zstr_len (haystack)); - } the - if(found) {WuyiReturn_long (Found-Zstr_val (haystack)); the}Else { - Return_false; Wu } -}
PHP built-in function Analysis Strpos ()