Jump to content

[SOLVED] echo message if no matches found


newbtophp

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/180673-solved-echo-message-if-no-matches-found/
Share on other sites

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!";

         }
   }
}


?>

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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.