php string matching with wildcard *?

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

    You're mixing up ending ($) and beginning (^). This:

    preg_match( '/$' . $pattern . '^/i' , $source );
    

    Should be:

    preg_match( '/^' . $pattern . '$/i' , $source );
    

提交回复
热议问题