如何检查输入是否包含数组之一?

I have an input like this:

<input name='postImg' type='text'><?php if(isset($error)){ echo $_POST['postImg'];}?></input>

I would like PHP to check if the input text contains: .png or .jpeg or .gif etc. To make sure its a image. But it has to be input name (so no upload).

How can I do this best?

You could use a regular expression. This will check that the extension is correct; matching (.png, .jpeg, .jpg, .gif) the end of the string

if( preg_match("/\.(png|jpeg|jpg|gif)$/", $_POST['postImg']) ) {
   //Yep.
}

Example: https://eval.in/208018

Edit

if( strlen($postImg) > 0 AND preg_match("/\.(png|jpeg|jpg|gif)$/", $postImg) == FALSE) {
   $error[] = 'Wrong image format.';
}

Try:

if(strpos($_POST['postImg'], '.png') || strpos($_POST['postImg'], '.jpeg') || strpos($_POST['postImg'], '.gif')) {
    echo 'It exists';
}