string sanitizer for filename

后端 未结 17 1293
长情又很酷
长情又很酷 2020-11-27 13:23

I\'m looking for a php function that will sanitize a string and make it ready to use for a filename. Anyone know of a handy one?

( I could write one, but I\'m worri

17条回答
  •  离开以前
    2020-11-27 14:07

    Making a small adjustment to Sean Vieira's solution to allow for single dots, you could use:

    preg_replace("([^\w\s\d\.\-_~,;:\[\]\(\)]|[\.]{2,})", '', $file)
    

提交回复
热议问题