You said preg_match()
, instead you should be using preg_match_all()
and there is no need to use the u
modifier in your regular expression here.
$str = "string: hi, it is string.";
preg_match_all('/[a-z]+/i', $str, $matches);
print_r($matches[0]);
Output
Array
(
[0] => string
[1] => hi
[2] => it
[3] => is
[4] => string
)