1
例子 1. dir() 例子请留意下面例子中检查 dir() 返回值的风格。我们明确地测试返回值是否全等于(值和类型都相同 - 更多信息参见比较运算符)FALSE,否则任何目录项的名称求值为 FALSE 的都会导致循环停止。 <?php
$d = dir("/etc/php5");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
echo $entry."\n";
}
$d->close();
?> 2.
$text = file_get_contents( $fname );
$text = str_replace( "aaa", "bbb", $text );
$fp = fopen( $fname, "w" );
fwrite( $fp, $text );
fclose( $fp );
例子 1. dir() 例子请留意下面例子中检查 dir() 返回值的风格。我们明确地测试返回值是否全等于(值和类型都相同 - 更多信息参见比较运算符)FALSE,否则任何目录项的名称求值为 FALSE 的都会导致循环停止。 <?php
$d = dir("/etc/php5");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
echo $entry."\n";
}
$d->close();
?> 2.
$text = file_get_contents( $fname );
$text = str_replace( "aaa", "bbb", $text );
$fp = fopen( $fname, "w" );
fwrite( $fp, $text );
fclose( $fp );
$d = dir($path);
while(false !== ($v = $d->read())) {
if($v == "." || $v == "..")
continue;
$file = $d->path."/".$v;
$m_name=$path.$v;
echo "<a href=\"$m_name\"><dt>$v</a>";
if(is_dir($file))
dirtree($file);
}
$d->close();
}