PHP built-in function Analysis Strpos ()

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.