Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Paul Hudson's Coding Academy Project 1

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
LinuxNoob



Joined: Fri Oct 08, 2010 4:15 pm
Posts: 2

PostPosted: Fri Oct 08, 2010 4:47 pm    Post subject: Paul Hudson's Coding Academy Project 1 Reply with quote

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
View user's profile Send private message
Ram
LXF regular


Joined: Thu Apr 07, 2005 10:44 pm
Posts: 1667
Location: Guisborough

PostPosted: Fri Oct 08, 2010 7:29 pm    Post subject: Reply with quote

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.....
Back to top
View user's profile Send private message MSN Messenger
LinuxNoob



Joined: Fri Oct 08, 2010 4:15 pm
Posts: 2

PostPosted: Sat Oct 09, 2010 10:34 am    Post subject: Reply with quote

Thanks Ram. That helped a lot. now, to continue with the rest of the book...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast