2016-07-25 10 views
1

preg_matchをfile_get_contentで正しく使うには?私はユーザーが誤った情報を入力した場合、ユーザーがログインできるフォームを持っています.file_get_contents内のデフォルトのエコーはpreg_matchを使用して新しいメッセージに置き換えられますが、機能しません。PHPを使用してfile_get_contentでpreg_matchを使用するにはどうすればよいですか?

私はPHPスニペットを持っていますが、白い空白のページしかありません。あなたは

$応答=のfile_get_contents($のURL、falseの場合、$コンテキスト)区切りの使用を使用する必要がありますパターンについては

$reply = file_get_contents($url, false, $context); 
if(preg_match($reply, 'No information was found'){ 
    echo("<script>location.href = '/page/message/';</script>"); 
} else { 
    echo $reply; 
    echo '<div> 
    For any other questions please contact us Monday - Sunday 9am - 6pm at <strong style="color: #000;">1235456</strong> or <strong style="color: #000;">[email protected]</strong> 
    </div>'; 
} 

答えて

2

if(preg_match('/No information was found/', $reply)){ 
    echo("<script>location.href = '/page/message/';</script>"); 
} else { 
    echo $reply; 
    echo '<div> 
    For any other questions please contact us Monday - Sunday 9am - 6pm at <strong style="color: #000;">1235456</strong> or <strong style="color: #000;">[email protected]</strong> 
    </div>'; 
} 

preg_match最初のパラメータは、あなたが2番目のパラメータで

をパターンを使用しているパターンです /区切り文字を追加します。
関連する問題