2016-12-23 159 views
-1

正如我切换到PHP7我有问题(未捕获的错误:调用未定义的函数额日格())EREG到的preg_match PHP7

我的问题是如何从的preg_match改变,因为当我改变的preg_match(“[0- 9] {1,2}”,$头)我得到的输出........

我下面的代码:

$prevodi = explode('@',$word['prevod']); 
    foreach ($zborovi as $zbor) 
    { 
     $atr = ""; 
     echo '<div class="words">'; 
     $tmpprev = $prevodi[$cnt]; 
     $pred = preg_split("[.]",trim($tmpprev)); 
     $len = strlen($tmpprev); 
     $cut = 0; 
     $lng = count($pred); 
     if ($lng > 1) 
     { 
      $cnt1 = 0; 
      while ($cnt1 < $lng-1) 
      { 
       $head = trim($pred[$cnt1]); 
       $cut = $cut + strlen($pred[$cnt1]) + 1; 
       $cnt1 = $cnt1 + 1; 
       if (preg_match("/\d{1,2}/", $head)) continue; 
       if (strpos($head,'(') === false || strpos($head,'(е)') !== false) $atr = $atr.$head.'. '; 
      } 
     } 
     echo '<span class="zbor_1">'.$zbor.'<span class="atribute">&nbsp;&nbsp;'.$atr.'</span></span><br />'; 
+0

包裹既然你切换到PHP 7,很明显,因为'PHP 5.3.0 ereg'已被弃用。 'ereg'没有正则表达式分隔符。 'preg_match'需要分隔符'/'或'#',这样就可以像'preg_match(“/ [0-9] {1,2} /”,$ head)'或'preg_match(“#[0-9 ] {1,2}#“,$ head)'。 – Perumal

+0

@ Perumal93这正是我的答案:)你可以投票,你知道... – Dekel

+0

我已经在你回答之前输入它。一旦你回答,该帖子被搁置,以避免进一步得到任何答案。因此我无法发布答案,并认为至少要提供评论意​​见。顺便说一下,我不反对对你的答案进行投票。完成。 :) – Perumal

回答

2

您可以使用

if (preg_match("/\d{1,2}/", $head)) 

取而代之。

顺便说一句,请注意,它也可能是preg_match("/[0-9]{1,2}/", $head)。唯一的区别是在preg_match这种模式应该在startend CHAR(它可以是任何的/#[email protected]

+0

我仍然输出不好,http://prntscr.com/dn8fa2。 –

+1

我不确定我在PHP 5.4上看到了什么 – Dekel

+0

我在PHP 7上得到这个http://prntscr.com/dn8gok输出我得到........... –