📜  php代码示例中的字符串匹配

📅  最后修改于: 2022-03-11 14:54:44.843000             🧑  作者: Mango

代码示例4
You could use regular expressions as its better for word matching compared to
strpos, as mentioned by other users. A strpos check for are will also return 
true for strings such as: fare, care, stare, etc. These unintended matches can 
simply be avoided in regular expression by using word boundaries.

A simple match for are could look something like this:

$a = 'How are you?';

if (preg_match('/\bare\b/', $a)) {
    echo 'true';
}