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 

PHP coding academy project 1

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



Joined: Tue Jul 27, 2010 5:10 pm
Posts: 1
Location: southwest UK

PostPosted: Tue Jul 27, 2010 6:45 pm    Post subject: PHP coding academy project 1 Reply with quote

Hi i have been going through the project 1 php academy book and have come across and experiencing problems! May be i am making a simple fault.

I have got to page 22 and all work well! Got the right output at the terminal. When i got to page 23 and added the extra code i start to get error's when running the script.

This was the page 23 code i added to the script.

chdir("..");
subdir_scan(".")

This is the complete code and error's.

Code:
<?php

function chdir("..");
   subdir_scan(".");

   subdir_scan($dir){
   $files = scandir($dir);
   foreach($files as $files){
      if ($files==".")continue;
      if ($files=="..")continue;

      print "$dir/$files\n";

      if (is_dir("$dir/$files")){
         subdir_scan("$dir/$files");
         }
      }
   }

subdir_scan(".")
?>


Error message.

Code:
PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE in /home/username/php/project1.php on line 3


Any help in what i have done wrong would be great! I'm sure it's a simple mistake i've made but i have checked over and over again!

I am a simple newbie forgive me for not spotting the problem. Confused
Back to top
View user's profile Send private message
Dutch_Master
LXF regular


Joined: Tue Mar 27, 2007 2:49 am
Posts: 2422

PostPosted: Tue Jul 27, 2010 8:56 pm    Post subject: Reply with quote

Actually, the solution is part of the error mesage:
Code:
PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE in /home/username/php/project1.php on line 3
The clue is in the last part:
Quote:
expecting '&' or T_VARIABLE in /home/username/php/project1.php on line 3
Now, look at your code, what's on line 3?
Code:
function chdir("..");
The PHP parser says it's invalid syntax. The question you now need to ask yourself is: "why is that invalid?" and go from there Smile
Back to top
View user's profile Send private message
leke
LXF regular


Joined: Mon Oct 22, 2007 6:45 pm
Posts: 500
Location: Oulu, Finland

PostPosted: Wed Jul 28, 2010 4:34 pm    Post subject: Reply with quote

Is it correct to put 'function' in front of chdir() -- an existing php function?
http://php.net/manual/en/function.chdir.php
_________________
I codes here: http://notsure.cz.cc/
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