PHP coding academy project 1

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

PHP coding academy project 1

Postby dansit » Tue Jul 27, 2010 5:45 pm

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: Select all
<?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: Select all
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. :?
dansit
 
Posts: 1
Joined: Tue Jul 27, 2010 4:10 pm
Location: southwest UK

Postby Dutch_Master » Tue Jul 27, 2010 7:56 pm

Actually, the solution is part of the error mesage:
Code: Select all
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:
expecting '&' or T_VARIABLE in /home/username/php/project1.php on line 3
Now, look at your code, what's on line 3?
Code: Select all
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 :)
Dutch_Master
LXF regular
 
Posts: 2460
Joined: Tue Mar 27, 2007 1:49 am

Postby leke » Wed Jul 28, 2010 3:34 pm

Is it correct to put 'function' in front of chdir() -- an existing php function?
http://php.net/manual/en/function.chdir.php
User avatar
leke
LXF regular
 
Posts: 507
Joined: Mon Oct 22, 2007 5:45 pm
Location: Oulu, Finland


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests