0
我正在寻找一种方法来测试RecursiveDirectoryIterator对象输出的一部分。 我知道如何识别一个文件夹,但我对PHP很陌生,不熟悉如何查看文件夹对象路径的内容......这可能吗?使用RecursiveDirectoryIterator在目录路径中查找字符串
我有以下几点:
foreach($files as $object){
$indent = str_repeat(' ', $files->getDepth());
if($object->isDir()){
//I know this is wrong... here is where I would want to find the string:
if($object contains 'mystring')){
echo "%%%-------found the string!\n";
}else{
echo $indent, "|| dir: $object\n";
}
}else{
echo $indent, "-- $object\n";
}
}
感谢您的帮助。 – jml 2013-03-20 19:11:28
我认为你的意思是'=='而不是'===',对吗?所以不会让我编辑这个改变,因为字符太少了。 – jml 2013-03-22 18:37:29
不,它是===。因为如果搜索项不包含,则strpos返回布尔值false,如果该字符串以搜索项开始,则返回0。因此,如果使用==,即使'mystring'是字符串的一部分,它也可能评估为“false”。看到警告在http://php.net/strpos – periklis 2013-03-22 21:10:39