老师发的代码让我们自己看,求大佬帮忙给个注释
1. 写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。
<?php
function my_scandir($dir){
$files=array();
if(is_dir($dir)){
if($handle=opendir($dir)){
while(($file=readdir($handle))!==false){
if($file!=”.” && $file!=”..”){
if(is_dir($dir.”/”.$file)){
$files[$file]=my_scandir($dir.”/”.$file);
}else{
$files[]=$dir.”/”.$file;
}
}
}
closedir($handle);
return $files;
}
}
}
print_r(my_scandir(“D:Program FilesInternet ExplorerMUI”));
?>
2.请写一个函数,实现以下功能:字符串“open_door” 转换成 “OpenDoor”、“make_by_id” 转换成 “MakeById”。
<?php
function changeStyle(& $str) {
/*$str = str_replace ( "_", "", $str );
$str = ucwords ( $str );
$str = str_replace ( " ","", $str );
return $str;*/
$arrStr=explode('_',$str);
foreach($arrStr as $key=>$value){
$arrStr[$key]=strtoupper(substr($value,0,1)).substr($value,1);
}
return implode('',$arrStr);
}
$s = "open_door";
echo changeStyle ( $s );
?>
<?php
function my_scandir($dir){
$files=array();
if(is_dir($dir)){
if($handle=opendir($dir)){
while(($file=readdir($handle))!==false){
if($file!=”.” && $file!=”..”){
if(is_dir($dir.”/”.$file)){
$files[$file]=my_scandir($dir.”/”.$file);
}else{
$files[]=$dir.”/”.$file;
}
}
}
closedir($handle);
return $files;
}
}
}
print_r(my_scandir(“D:Program FilesInternet ExplorerMUI”));
?>
2.请写一个函数,实现以下功能:字符串“open_door” 转换成 “OpenDoor”、“make_by_id” 转换成 “MakeById”。
<?php
function changeStyle(& $str) {
/*$str = str_replace ( "_", "", $str );
$str = ucwords ( $str );
$str = str_replace ( " ","", $str );
return $str;*/
$arrStr=explode('_',$str);
foreach($arrStr as $key=>$value){
$arrStr[$key]=strtoupper(substr($value,0,1)).substr($value,1);
}
return implode('',$arrStr);
}
$s = "open_door";
echo changeStyle ( $s );
?>
...全文


基础编程
