preg_match-使用模式数组-PHP

preg_match-使用模式数组-PHP,php,regex,Php,Regex,我有一个文本数组和一个模式数组。我试图在文本数组中的每个元素中搜索模式数组中的所有模式。然而,我得到了下面的错误,我不明白我错在哪里 $participantVcRoomName = '/PR GMVC RP K GRAY/i'; $sipURI = '/+13135539892/i'; $row = '¤¤AdhocCallAdded¤¤+13135539892@11.198.0.54'; $row2 = '¤¤SentMessageToSystem¤¤The conference was e

我有一个文本数组和一个模式数组。我试图在文本数组中的每个元素中搜索模式数组中的所有模式。然而,我得到了下面的错误,我不明白我错在哪里

$participantVcRoomName = '/PR GMVC RP K GRAY/i';
$sipURI = '/+13135539892/i';
$row = '¤¤AdhocCallAdded¤¤+13135539892@11.198.0.54';
$row2 = '¤¤SentMessageToSystem¤¤The conference was extended, the new end time 
is: 10:45 AM¤¤PR GMVC RP K GRAY';
$row3 = '¤¤ConferenceEndTimeChanged¤¤09/13/2017 15:30:00 -05:00¤¤09/13/2017 
 10:30:00 -05:00';

$arrayDescp = [$row, $row2, $row3];
$arrayPatterns = [$participantVcRoomName, $sipURI];

foreach($arrayDescp  as $target){

    foreach($arrayPatterns as $aPattern) {

        $match = preg_match($aPattern, $target);
        if($match){
            echo 'match<br>';
        }else{
            echo 'no match<br>';
        }

    }
}
$participantVcRoomName='/PR GMVC RP K GRAY/i';
$sipURI='/+13135539892/i';
$row='·附加呼叫已添加+13135539892@11.198.0.54';
$row2='·发送消息到系统·会议延长,新的结束时间
is:10:45 AM·PR GMVC RP K GRAY';
$row3='?会议结束时间更改?2017年9月13日15:30:00-05:00?2017年9月13日
10:30:00 -05:00';
$arrayDescp=[$row,$row2,$row3];
$arrayPatterns=[$participantVcRoomName,$sipURI];
foreach($arrayDescp作为$target){
foreach($ArrayPattern作为$Apartern){
$match=preg_match($apatern,$target);
如果($match){
回声“匹配
”; }否则{ 回显“不匹配
”; } } }
错误消息:

preg_match()
:编译失败:在偏移量0处没有要重复的内容


您没有在数组中指定要检查的索引。将代码替换为以下内容:

$participantVcRoomName = '/PR GMVC RP K GRAY/i';
$sipURI = '/+13135539892/i';
$row = '¤¤AdhocCallAdded¤¤+13135539892@11.198.0.54';
 $row2 = '¤¤SentMessageToSystem¤¤The conference was extended, the new end 
 time 
 is: 10:45 AM¤¤PR GMVC RP K GRAY';
 $row3 = '¤¤ConferenceEndTimeChanged¤¤09/13/2017 15:30:00 -05:00¤¤09/13/2017 
 10:30:00 -05:00';

 $arrayDescp = [$row, $row2, $row3];
 $arrayPatterns = [$participantVcRoomName, $sipURI];
 $t=0;
 foreach($arrayDescp  as $target){

 foreach($arrayPatterns as $aPattern){

   $match = preg_match($aPattern, $target[$t]);
   if($match){
      echo 'match<br>';
   }else{
    echo 'no match<br>';
      }

   }
 $t++;
}
$participantVcRoomName='/PR GMVC RP K GRAY/i';
$sipURI='/+13135539892/i';
$row='·附加呼叫已添加+13135539892@11.198.0.54';
$row2='·发送消息到系统·会议延长,新的结束
时间
is:10:45 AM·PR GMVC RP K GRAY';
$row3='?会议结束时间更改?2017年9月13日15:30:00-05:00?2017年9月13日
10:30:00 -05:00';
$arrayDescp=[$row,$row2,$row3];
$arrayPatterns=[$participantVcRoomName,$sipURI];
$t=0;
foreach($arrayDescp作为$target){
foreach($ArrayPattern作为$Apartern){
$match=preg_match($apatern,$target[$t]);
如果($match){
回声“匹配
”; }否则{ 回显“不匹配
”; } } $t++; }
您没有在数组中指定要检查的索引。将代码替换为以下内容:

$participantVcRoomName = '/PR GMVC RP K GRAY/i';
$sipURI = '/+13135539892/i';
$row = '¤¤AdhocCallAdded¤¤+13135539892@11.198.0.54';
 $row2 = '¤¤SentMessageToSystem¤¤The conference was extended, the new end 
 time 
 is: 10:45 AM¤¤PR GMVC RP K GRAY';
 $row3 = '¤¤ConferenceEndTimeChanged¤¤09/13/2017 15:30:00 -05:00¤¤09/13/2017 
 10:30:00 -05:00';

 $arrayDescp = [$row, $row2, $row3];
 $arrayPatterns = [$participantVcRoomName, $sipURI];
 $t=0;
 foreach($arrayDescp  as $target){

 foreach($arrayPatterns as $aPattern){

   $match = preg_match($aPattern, $target[$t]);
   if($match){
      echo 'match<br>';
   }else{
    echo 'no match<br>';
      }

   }
 $t++;
}
$participantVcRoomName='/PR GMVC RP K GRAY/i';
$sipURI='/+13135539892/i';
$row='·附加呼叫已添加+13135539892@11.198.0.54';
$row2='·发送消息到系统·会议延长,新的结束
时间
is:10:45 AM·PR GMVC RP K GRAY';
$row3='?会议结束时间更改?2017年9月13日15:30:00-05:00?2017年9月13日
10:30:00 -05:00';
$arrayDescp=[$row,$row2,$row3];
$arrayPatterns=[$participantVcRoomName,$sipURI];
$t=0;
foreach($arrayDescp作为$target){
foreach($ArrayPattern作为$Apartern){
$match=preg_match($apatern,$target[$t]);
如果($match){
回声“匹配
”; }否则{ 回显“不匹配
”; } } $t++; }
这个
+
是正则表达式中的一个特殊字符,一个表示1或更多的量词。由于在该量词之前没有任何字符(-set)——它是正则表达式中的第一个实体,位于分隔符之后——因此会出现该错误

如果你想匹配一个普通的
+
,你需要避开它:

$sipURI = '/\+13135539892/i';
            ^^ a literal `+`

.

在正则表达式中,
+
是一个特殊字符,一个表示1或更多的量词。由于在该量词之前没有任何字符(-set)——它是正则表达式中的第一个实体,位于分隔符之后——因此会出现该错误

如果你想匹配一个普通的
+
,你需要避开它:

$sipURI = '/\+13135539892/i';
            ^^ a literal `+`