php string matching with wildcard *?

后端 未结 6 1007
悲&欢浪女
悲&欢浪女 2021-02-06 23:18

I want to give the possibility to match string with wildcard *.

Example

$mystring = \'dir/folder1/file\';
$pattern = \'dir/*/file\';

string         


        
6条回答
  •  别跟我提以往
    2021-02-06 23:29

    You should just use .* instead.

    $pattern = str_replace( '*' , '.*', $pattern);   //> This is the important replace
    

    Edit: Also your ^ and $ were in the wrong order.

    Working demo: http://www.ideone.com/mGqp2

提交回复
热议问题