2016-12-23 104 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輸出我得到........... –