我需要preg_match
才能找到字符串中的所有单词。
例如:
$str = "string: hi, it is string.";
我想得到这个:
[0] => string
[1] => hi
[2] => it
[3] => is
[4] => string
我与'/[a-z]+/ui'
一起使用,但我明白了:
[0] => string:
[1] => hi,
[2] => it
[3] => is
[4] => string.
答案 0 :(得分:1)
你说preg_match()
,而你应该使用preg_match_all()
,而且你的正则表达式中不需要使用u
修饰符。
$str = "string: hi, it is string.";
preg_match_all('/[a-z]+/i', $str, $matches);
print_r($matches[0]);
输出
Array
(
[0] => string
[1] => hi
[2] => it
[3] => is
[4] => string
)