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

         }
   }
}


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.