1

我见过这个...

preg_match("/.*" . $row['keyword'] . ".*/", $word, $matches);

该模式试图暗示什么?

4

4 回答 4

3

这意味着找到后面或前面有 0 个或多个字符 ( *) 而不是\n( .) 的术语。

除非它在其他地方完成,否则你应该$row['keyword']preg_quote($row['keyword'], '/').

于 2012-04-11T03:32:08.987 回答
3

解释 :

/                            # start of the regex
.                            # match anything (any character, etc - except for /n)
*                            # zero or more times
" . $row['keyword']. "       # match the keyword
.*                           # same as above
/                            # end of the regex
于 2012-04-11T03:34:44.980 回答
1

/只是模式分隔符,.*意思是“任何字符(换行符除外)重复 0 次或多次”,所以它只是搜索出现在$row['keyword'], in 中的任何字符串$word

于 2012-04-11T03:33:34.460 回答
1

它试图找出是否$row['keyword']包含在中,如果关键字包含元字符,例如,等,$word调用它也更安全preg_quote$row['keyword']*/\

于 2012-04-11T03:33:43.103 回答