从句子中拉出单词

问题描述

| 有没有一种方法可以使用PHP在句子中查找单词?我们有一个表格,在主题行中,如果某人使用交付,交付或交付这两个字,我们希望将其重定向。能做到这一点吗?感谢您在此问题上的任何帮助。     

解决方法

        应该这样做:
if ( preg_match(\'/deliver(?:y|ed)?/i\',$subject) )
{
  // Redirect
}
    ,        您可以使用
strpos
函数在另一个字符串中搜索一个字符串。如果找不到该字符串,将返回
false
,并且您知道找不到该字符串。     ,        这里:
<?php
if (strpos($string,\"deliver\")) {
   header(\"Location: somepage.php\");

}
?>
    ,        另一种方法:
if (stristr($sentence,\"deliver\")) {
header(\'location: somepage.php\');
}
但是我会使用之前表达的preg_match。     ,        一种方法:
if (preg_match(\'/deliver(y|ed)?/\',$string)) {
    // yes,$string contained \'deliver\',\'delivery\' or \'delivered\'
}
    ,         提取所有单词,简单地使用空格字符将字符串爆炸 使用简单的strpos()函数或正则表达式模式匹配来检查特定单词
preg_match(\"/(?:^|\\s+)deliver(y|ed)?(?:$|\\s+)/i\")
上面的表达式检查空格字符或字符串开头,相似空格字符或字符串结尾