Php search string (with wildcards)

后端 未结 5 798
自闭症患者
自闭症患者 2021-01-05 03:27

Is there a way to put a wildcard in a string? The reason why I am asking is because currently I have a function to search for a substring between two substrings (i.e grab th

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 04:16

    This is one of the few cases where regular expressions are actually helpful. :)

    if (preg_match('/my (\w+) has/', $str, $matches)) {
        echo $matches[1];
    }
    

    See the documentation for preg_match.

提交回复
热议问题