Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • preg_match_all php functions

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 296
    Comment on it

    Welcome to FindNerd. We are going to discuss the function preg_match_all which will match the substring from the string. It try multiple times for matching pattern. Please have a look.

    <?php
    $str = "tird";
    preg_match_all('/ti[rte]d/',$str,$matches);
    ?>
    

    In above example you can match the different type of string such as tird,titd,tied. This function is useful to get multiple matches at same. We have tried the simple pattern. Now we will try the meta characters to build the pattern. Please check the list.
    A) .(Full stop)
    B) .(Carat)
    C) + (Plus)
    D) ?(Question mark)
    E) [(opening braces)
    F) ] (closing braces)
    G) { (opening curly braces)
    H) } (closing curly braces)
    I) Backslash ()
    J) | (Pipe)
    K) ( (opening parens)
    L) ) (closing parens)

    We are going to take an example with these meta characters. Please have a look.

    <?php
    $str = "Billon"
    preg_match_all('/Bi*l/',$str,$matches);
    ?>
    result: Array ( [0] => Array ( [0] => Bil ) ) 
    

    In above example we set the two character in the pattern that are B and i. and search for l in the string.

 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: