本文共 866 字,大约阅读时间需要 2 分钟。
我想扫描目录和子目录,制作xml文件列表,从xml文件中获取内容并显示它.此功能无需OOP即可正常工作.我尝试创建一个类.我从函数main调用函数scandir_through.我没有错误,结果也是如此.
class data {
var $dir = 'D:\wamp4\www\begin';
public function scandir_through($dir)
{
$items = glob($dir . '/*');
for ($i = 0; $i < count($items); $i++) {
if (is_dir($items[$i])) {
$add = glob($items[$i] . '/*');
$items = array_merge($items, $add);
}
}
return $items;
}
public function main()
{
$scan_tree = $this->scandir_through($dir);
echo "
- "."";
foreach ($scan_tree as $key=>$file){
$url = $file;
$xml = simplexml_load_file($url);
$book_count = count($xml->book);
for($i = 0; $i < $book_count; $i++) {
$book = $xml->book[$i];
$title=$xml->book[$i]->title;
$author=$xml->book[$i]->author;
//echo '';
//echo $file. "   ";
//echo $title. "   ";
//echo $author;
echo "
}
}
echo "
";}
}
$d = new data();
$d->main();
?>
转载地址:https://blog.csdn.net/weixin_32473663/article/details/115163993 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!