Reputation: 43
I actually try to reimplement some functionality of a component to provide proper utf-8 support. Is it possible to perform a global (iterative) match (g modifier, which in preg_match it is set by default)?
$pattern = 'du\@de\.com';
$whitespacedDude = ' du \@ de\. com ';
$globalDude = 'a global [email protected]';
$dude = '[email protected]';
var_dump(preg_match("/$pattern/", $globalDude, $matches));
var_dump(preg_match("/$whitespacedDude/x", $dude, $matches));
var_dump(mb_ereg_match("$pattern", $globalDude));
var_dump(mb_ereg_match("$whitespacedDude", $dude, 'x'));
Gives:
true
true
false // this one should be true
true
Actually im doing a workaround via mb_ereg_search
to simulate the global matching. Is there another/better way?
Thank you.
Upvotes: 2
Views: 403
Reputation: 198194
mb_ereg_match
tests for matches from the beginning only. You need to change your pattern and allow any characters upfront:
var_dump(mb_ereg_match(".*$pattern", $globalDude));
Upvotes: 1