-1
<form action="" method="post">
<?php if($input !== null){   //if input is submitted then show message
   if(strpos($input, '[key1]') === true or strpos($input, 'key2') === true) { //find the input [key1] or [key2] 
     echo " input contain [key1] or [key2] ";
   }else{ // input doesnt contain [key1] or [key2]
     echo " input didnt contain [key1] or [key2]";
   }
}else{ // showing form input
echo "
   <input type='text' name='inputText' maxlength='100' data-length=100 class='form-control char-textarea' rows='3' placeholder='use [key1] or [key2]' required aria-invalid='false'/>
   <input type='file' name='fileToUpload' id='fileToUpload' ><br>
   <button type='submit' name='SubmitButton' class='btn btn-primary mr-1 mb-1'>Send</button>
    ";
}?>
</form> 

here the form i made, now how can i find if the input is contain [key1]or[key2] when they submit the form, i tried

if(strpos($input, '[key1]') === true or strpos($input, 'key2') === true)

but the result is echo " input didnt contain [key1] or [key2]"; and not echo " input contain [key1] or [key2] ";

Tunku Salim
  • 167
  • 1
  • 9

1 Answers1

0

strpos returns either an integer (position if the string found) or false if the string is not found. So your test

if(strpos($input, '[key1]') === true or strpos($input, 'key2') === true)

will never pass, since an integer or false can never be === true. Instead, change your test to check the result of strpos is not false:

if(strpos($input, '[key1]') !== false or strpos($input, 'key2') !== false)
Nick
  • 138,499
  • 22
  • 57
  • 95