Checking for file-extensions in PHP with Regular expressions

前端 未结 7 2132
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 17:30

I\'m reading all the files in a single directory and I want to filter on JPG,JPEG,GIF and PNG.

Both capital and small letters. Those are the only files to be accepte

7条回答
  •  不知归路
    2020-12-28 17:52

    I think something is wrong with your regex. Try testing regexes here first: https://www.regexpal.com/

    I think this one might work for you:

    /^.*\.(jpg|jpeg|png|gif)$/i

    Note the /i at the end - this is the "case insensitive" flag, saves you having to type out all permutations :)

提交回复
热议问题