PHP preg_match and preg_match_all functions

后端 未结 3 1393
野性不改
野性不改 2020-12-01 05:14

I would like to know what the preg_match and preg_match_all functions do and how to use them.

3条回答
  •  一整个雨季
    2020-12-01 05:56

    A concrete example:

    preg_match("/find[ ]*(me)/", "find me find   me", $matches):
    $matches = Array(
        [0] => find me
        [1] => me
    )
    
    preg_match_all("/find[ ]*(me)/", "find me find   me", $matches):
    $matches = Array(
        [0] => Array
            (
                [0] => find me
                [1] => find   me
            )
    
        [1] => Array
            (
                [0] => me
                [1] => me
            )
    )
    
    preg_grep("/find[ ]*(me)/", ["find me find    me", "find  me findme"]):
    $matches = Array
    (
        [0] => find me find    me
        [1] => find  me findme
    )
    

提交回复
热议问题