Paul Hudson's Coding Academy Project 1

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Paul Hudson's Coding Academy Project 1

Postby LinuxNoob » Fri Oct 08, 2010 3:47 pm

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]
LinuxNoob
 
Posts: 2
Joined: Fri Oct 08, 2010 3:15 pm

Postby Ram » Fri Oct 08, 2010 6:29 pm

Typo in your code,

ob_get_cleaned() should read ob_get_clean()

lubuntu LXDE 13.10 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
User avatar
Ram
LXF regular
 
Posts: 1682
Joined: Thu Apr 07, 2005 9:44 pm
Location: Guisborough

Postby LinuxNoob » Sat Oct 09, 2010 9:34 am

Thanks Ram. That helped a lot. now, to continue with the rest of the book...
LinuxNoob
 
Posts: 2
Joined: Fri Oct 08, 2010 3:15 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest