Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • strchr and strrchr in PHP

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 385
    Comment on it

    Hello Readers,

    1> Both strchr and strrchr are the string functions.

    2> strchr is an alias of strstr.

    3> strchr returns the part of haystack string starting from and including the first occurrence of needle to the end of haystack and strrchr function returns the portion of haystack which starts at the last occurrence of needle and goes until the end of haystack.

    4> Syntax of strchr:

     strchr(string_name, search_string, before_search)
    

    Syntax of strrchr:

    strrchr(string,char)
    

    5> strchr function is case-sensitive. For a case-insensitive search, use stristr() function.

    6> Example of strchr and strrchr

    $s = 'This is a Web';//Here the given string
    
    $first = strchr($s, 's');//First use the strchr
    
    $last = strrchr($s, 's');//second use the strrchr
    
    echo $first;//Print the strchr
    
    output:
    
    s is a Web
    
    echo $last;//print the strrchr
    
    output:
    
    st 
    

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: