PHP string function strstr stristr strchr STRRCHR

Source: Internet
Author: User
    • Strstr--Finds the first occurrence of a string, returning the string starting at the first occurrence to the end or beginning of the string.
    • STRISTR--Ignoring case version of the STRSTR function
    • STRCHR--alias of the STRSTR function
    • STRRCHR--Finds the last occurrence of a string, returning the string from the last occurrence to the end of the string.

Strstr

Finds the first occurrence of a string, returning the string from the first occurrence to the end or beginning of the string.

Mixed Strstr (String $haystack, mixed $needle [, bool $before _needle = false])  

Parameter description

The haystack is searched in the string. needle If needle is not a string, it will be converted to an integer and used as the sequential value of the character. Before_needle If TRUE,STRSTR () returns the portion of the needle before the position in haystack.

return value

Success: Return a part of string needle before or after failure: If needle is not found, FALSE is returned.

Attention

    1. The function is case-sensitive
    2. If you only want to determine if needle exists in haystack, use the strpos () function, which is faster and consumes less memory

Example

 
  
 
  
 
  
 
  

Stristr

Ignoring case versions of the STRSTR () function

Mixed Stristr (String $haystack, mixed $needle [, bool $before _needle = false])  

The only difference between this function and Strstr () is that it is case insensitive. Other references are strstr ()

 
  

Strchr

Alias of the Strstr () function

Mixed STRCHR (String $haystack, mixed $needle [, bool $before _needle = false])  

The function is equivalent to STRSTR (). Other references are strstr ()

$email  = ' name@example.com '; $behind = STRCHR ($email, ' a '); echo $behind;//Print Ame@example.com$front = STRCHR ($email, ' A ', true); From PHP 5.3.0 echo $front; Print n  ?>

Strrchr

Finds the last occurrence of a string, returning the string from the last occurrence to the end of the string.

Mixed STRRCHR (String $haystack, mixed $needle)  

Parameter description

The haystack is searched in the string. needle If the needle contains more than one character, only the first character is used. This behavior differs from strstr (). If needle is not a string, it is converted to an integer and is treated as a character order value.

return value

Success: Return part of String needle after failure: If needle is not found, FALSE is returned.

Example

 
  
/* "Needle is string" *  /$email = ' name@example.com '; $behind = STRRCHR ($email, ' am '); echo $behind;//Print ample.com  ;
 
  

OneAPM for PHP is able to drill down into all of the PHP applications to perform application performance management in-depth application performance management and monitoring within all PHP applications, including code-level visibility, rapid identification and traceability of performance bottlenecks, real user experience monitoring, Server monitoring and end-to-end application performance management. To read more technical articles, please visit the ONEAPM Official technology blog.

  • 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.