PHPで以下のIF条件を記述する方法はありますか? ありがとうPHPの短期間のIF条件
if (($ext != 'jpg') OR ($ext != 'png') OR ($ext !='jpeg') OR ($ext != 'gif'))
{
$error = 'Image type not allowed.';
}
PHPで以下のIF条件を記述する方法はありますか? ありがとうPHPの短期間のIF条件
if (($ext != 'jpg') OR ($ext != 'png') OR ($ext !='jpeg') OR ($ext != 'gif'))
{
$error = 'Image type not allowed.';
}
if (!in_array($ext, array('jpg', 'png', 'jpeg', 'gif')){
$error = 'Image type not allowed.';
}
if (!in_array($ext, array('jpg','png','jpeg','gif')))
$error = 'Image type not allowed.';
または
if(!preg_match('/^(jpe?g|png|gif)$/',$ext))
$error = 'Image type not allowed.';
(!in_array($ EXT、配列( 'JPG'、 'JPEG'、 'GIF)) { $エラー=' 画像タイプでない場合。許可 ';}
上記のすべての答えは正しいですが、別の何かのために:
$error = (!in_array($ext, array('jpg','png','jpeg','gif'))) ? 'Image type not allowed.' : '';
これは意味的には同等ではありません - 'isset($ error)'はこの後に別のものになります – tobyodavies
@tobyodavies - それは異なっています –