Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Search For a Specific Text Within a String

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    In PHP, to search for a specific text within a string a function strpos() is used. It includes 3 parameters:

    • string: It is required parameter which specify the string to search.
    • find: It is also a required parameter which specify the string to find.
    • start: It is an optional field that specify where to begin the search.

    Syntax:

    strpos(string, find, start)
    

    It returns the position of the first occurence of the string inside another or false if the string not found. The position of the string start at 0.

    For example:

    <?php
    $str = "String in which you search the sub-string" ;
    $find="sub";
    echo strpos($str, $find);
    ?>
    

    The output of the above code is:

    31
    

 0 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: