On 27 January 2004 05:50, Paul Furman wrote:

> Shawn McKenzie wrote:
> > I've noticed in both of your posts that you aren't terminating the
> > line before the include with a ;
> 
> Yup, thanks!
> 
> Then I fixed my global problem without bugging you guys too.

Actually, no you didn't -- you just bypassed it.

> Final result:
> 
> 
> #call.php
>    $dirstr= "./";
>    include 'scandir.php';
>    scandir('$dirstr');

Becasue single-quoted strings don't do variable interpolation, you are
actually passing the literal string '$dirstr' to the function -- no the
*value* of $dirstr, which is what you want.  If you needed to use quotes
here, they should be double ones -- but, actually, you don't need quotes at
all: since what you really you want is the value of $dirstr, this will do
the trick:

    scandir($dirstr);

> #scandir.php
>    function scandir($dirstr) {

Well, now this $dirstr will be set to '$dirstr', which clearly isn't a valid
directory path!

>       global $dirstr; #I HAD TO ADD THIS LINE ALSO

But you've now bypassed that by equivalencing it to the global version of
$dirstr, which, of course, still contains './', so the rest of the function
works.  Once you take the quotes off the function call above, you also won't
need this global statement.

>       $files = array();
>       $fh = opendir($dirstr);
>       while (false !== ($filename = readdir($fh))) {
>           array_push($files, $filename);
>       }
>       closedir($fh);
>       return $files;
>    }
> 
>  > FYI...
>  > If you use / then you don't have to escape it like // only the \.
>  > Also, instead of ".\\" you can use '.\'

Actually, no you can't, because in single quoted strings \' is the sequence
to insert a single quote!  So you still ahve ti use '.\\'.

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to