检查一个字符串以获取有效的目录名称 [英] Check a string for a valid directory name
本文介绍了检查一个字符串以获取有效的目录名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个本地或用户的功能来检查字符串是否是有效的目录名。
我已经看过了PHP文档,我只能找到函数 is_dir
,它检查它是否是现有目录,而不是一个有效的名称一个目录。
I need a function, native or user made, that checks if a string is a valid directory name.
I've had a look through the PHP documentation and I can only find the function is_dir
which checks if it's an existing directory or not and not a valid name for a directory.
推荐答案
这应该适合你。
if (strpbrk($filename, "\\/?%*:|\"<>") === FALSE) {
/* $filename is legal; doesn't contain illegal character. */
}
else {
/* $filename contains at least one illegal character. */
}
这篇关于检查一个字符串以获取有效的目录名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文