newbtophp Posted November 7, 2009 Share Posted November 7, 2009 Ok, I have the following code, but i want to echo a message if no matches were found on any of the if statements. <?php if (isset($_FILES['file'])) { $file = file_get_contents($_FILES['file']['tmp_name']); $submit = $_POST['submit']; if($file == "") echo "error"; else { if($submit == "Submit") { //pattern is actually a regex pattern if(preg_match('/pattern1/', $file)) { include "somepage1.php"; } if(preg_match('/pattern2/', $file)) { include "somepage2.php"; } if(preg_match('/pattern3/', $file)) { include "somepage3.php"; } if(preg_match('/pattern4/', $file)) { include "somepage4.php"; } } } } ?> All help is greatly apreciated. Quote Link to comment https://forums.phpfreaks.com/topic/180673-solved-echo-message-if-no-matches-found/ Share on other sites More sharing options...
wildteen88 Posted November 7, 2009 Share Posted November 7, 2009 What specific "patterns" are you trying to match? Does the uploaded file need to be in a certain format? You need to be more clear with your question. Quote Link to comment https://forums.phpfreaks.com/topic/180673-solved-echo-message-if-no-matches-found/#findComment-953209 Share on other sites More sharing options...
newbtophp Posted November 7, 2009 Author Share Posted November 7, 2009 What specific "patterns" are you trying to match? Does the uploaded file need to be in a certain format? You need to be more clear with your question. Uploaded file needs to be .php, i already have an if statement to validate the file extension. Im matching a variety of of code, and the regex is quite long theirfore i renamed to pattern1 ...pattern2 etc, to post just the relevant code. Im looking for something abit like this , some sort of else with echos if none of the preg_matches are true (match). <?php if (isset($_FILES['file'])) { $file = file_get_contents($_FILES['file']['tmp_name']); $submit = $_POST['submit']; if($file == "") echo "error"; else { if($submit == "Submit") { if(preg_match('/pattern1/', $file)) { include "somepage1.php"; } if(preg_match('/pattern2/', $file)) { include "somepage2.php"; } if(preg_match('/pattern3/', $file)) { include "somepage3.php"; } if(preg_match('/pattern4/', $file)) { include "somepage4.php"; } else { echo "none of the above matches were found!"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180673-solved-echo-message-if-no-matches-found/#findComment-953211 Share on other sites More sharing options...
Garethp Posted November 7, 2009 Share Posted November 7, 2009 Also, another idea from the previous one I gave you if(preg_match('~Pattern1~', $Input) { } else if(preg_match('~Pattern2~', $Input)) { } else if(preg_match('~Pattern3~', $Input)) { } else { echo "None of the patterns were matched"; } Quote Link to comment https://forums.phpfreaks.com/topic/180673-solved-echo-message-if-no-matches-found/#findComment-953293 Share on other sites More sharing options...
newbtophp Posted November 7, 2009 Author Share Posted November 7, 2009 Thanks gareth that did the trick! Quote Link to comment https://forums.phpfreaks.com/topic/180673-solved-echo-message-if-no-matches-found/#findComment-953336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.