I want to give the possibility to match string with wildcard *.
*
Example
$mystring = \'dir/folder1/file\'; $pattern = \'dir/*/file\'; string
You're mixing up ending ($) and beginning (^). This:
$
^
preg_match( '/$' . $pattern . '^/i' , $source );
Should be:
preg_match( '/^' . $pattern . '$/i' , $source );