2016-05-12 6 views
0

プラス記号をエスケープする際に問題があります。バックスラッシュを試しましたが、効果はありません。preg_matchの+記号をエスケープする

function degree_of_interest() 
{ 
    $program = $_REQUEST['degree_of_interest']; 
    $highest_level = $_REQUEST['college_1_degree']; 
    $start = $_REQUEST['start_date']; 

    if(!preg_match("/\A(1-2 months|3-4 months|6+ months)\Z/i",$start) 
    OR !preg_match("/\A(Bachelors)\Z/i",$highest_level) 
    OR !preg_match("/\A(JD \(Juris Doctor\))\Z/i",$program)) 
    { 
     $this->errorsArray['degree_of_interest'][] = "For $program you must have a Bachelors degree"; 
    } 

} 

答えて

0

文字列を操作する場合は、すべての文字列エスケープルールに加えて、正規表現エスケープルールを適用する必要があります。

つまり、と入力すると、エスケープする必要があります。あなたの正規表現(文字列として)は次のようになります:

"/\\A(1-2 months|3-4 months|6\\+ months)\\Z/i" 
関連する問題