php string matching with wildcard *?

后端 未结 6 1015
悲&欢浪女
悲&欢浪女 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:28

    The one problem you'll have is that the call to preg_quote() will escape the asterisk character. Given that, your str_replace() will replace the *, but not the escape character in front of it.

    Therefore you should change the str_replace('*' ..) with str_replace('\*'..)

提交回复
热议问题