| View previous topic :: View next topic |
| Author |
Message |
LinuxNoob
Joined: Fri Oct 08, 2010 4:15 pm Posts: 2
|
Posted: Fri Oct 08, 2010 4:47 pm Post subject: Paul Hudson's Coding Academy Project 1 |
|
|
Following all the instructions in the booklet i have gotten so far as to run a function that prints out the root directory and all its subdirectories and then saving it to a output file. Now two things i want to know,
1. Does this code
<?php
function subdir_scan($dir){
$files = scandir($dir);
foreach($files as $file){
if($file == ".") continue;
if($file == "..") continue;
print"$dir/$file\n";
if(is_dir("$dir/$file")){
subdir_scan("$dir/$file");
}
}
}
chdir("..");
ob_start();
subdir_scan(".");
$output = ob_get_cleaned();
echo $output
?>
save what is being generated automatically or do i have to run the command php project01.php > output in the command line ?
Because when i run in the command line i get this error...
PHP Fatal error: Call to undefined function ob_get_cleaned() in /home/neels/PHP/project01.php on line 23
but the output.txt does get created in the local directory i created for this purpose.
2. When i run the next piece of code to compare the results
<?php
function subdir_scan($dir){
$files = scandir($dir);
foreach($files as $file){
if($file == ".") continue;
if($file == "..") continue;
print"$dir/$file\n";
if(is_dir("$dir/$file")){
subdir_scan("$dir/$file");
}
}
}
chdir("..");
ob_start();
subdir_scan(".");
$new_run = ob_get_cleaned();
$old_run = file_get_contents("output");
$new_array = explode("\n",$new_run);
$old_array = explode("\n",$old_run);
?>
It seems it does not do what its suppose to do, or am i doing something wrong ? [/code] |
|
| Back to top |
|
 |
Ram LXF regular

Joined: Thu Apr 07, 2005 10:44 pm Posts: 1550 Location: Guisborough
|
Posted: Fri Oct 08, 2010 7:29 pm Post subject: |
|
|
Typo in your code,
ob_get_cleaned() should read ob_get_clean() _________________
Ubuntu LXDE 12.04 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
|
|
| Back to top |
|
 |
LinuxNoob
Joined: Fri Oct 08, 2010 4:15 pm Posts: 2
|
Posted: Sat Oct 09, 2010 10:34 am Post subject: |
|
|
| Thanks Ram. That helped a lot. now, to continue with the rest of the book... |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|