RE: [PHP] unexpected include parse error
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
RE: [PHP] unexpected include parse error
On 27 January 2004 05:18, Shawn McKenzie wrote: PS I'm on my windows apache server but the forward slash seems to work in php that keeps it portable. I tried it both ways. Yes -- PHP internally translates between / and \ on Windows, precisely for portability reasons. Thus, you can write your code using / and port it easily between Windows and *n*x systems -- this is a boon if, like me, you do development work on a Windows server but have a *n*x server for your live site. 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
Re: [PHP] unexpected include parse error
the \ has to be slashed .\\; -Dave At 11:27 PM 1/26/2004, Paul Furman wrote: I'm new so probably missing something easy or doing something terribly wrong but I have spent a lot of time experimenting... ?php $dirstr= ./ include 'scandir.php'; scandir('$dirstr'); ? parse error, unexpected T_INCLUDE in [the above file] if I comment out the $dirstr= ./ above that error goes away and the scandir.php include runs (that's a php5 function that needs to be defined manually in PHP 4.3.4) #scandir.php ?php #$dirstr=.\; function scandir($dirstr) { $files = array(); $fh = opendir($dirstr); while (false !== ($filename = readdir($fh))) { array_push($files, $filename); } closedir($fh); return $files; } ? If I set $dirstr=.\; in the function it gives these errors: Parse error: unexpected $end in scandir.php at? last line Fatal error: Call to undefined function: scandir() in showdir.php If I don't set $dirstr at all, it runs the scandir function and fouls up in expected ways: Warning: opendir($dirstr): failed to open dir: Invalid argument in scandir.php Warning: readdir(): supplied argument is not a valid Directory resource in scandir.php Warning: closedir(): supplied argument is not a valid Directory resource in scandir.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] unexpected include parse error
David Obrien wrote: the \ has to be slashed .\\; Ah great, thanks! that fixes most of the errors. The following runs where I define the $dirstr in the function but if I try to define it in the page that calls the function, it still gives Parse error, unexpected T_INCLUDE in [#call] #call $dirstr= .// this is where I want to define the directory include 'scandir.php'; scandir('$dirstr'); #function function scandir($dirstr) { $files = array(); #$dirstr=.//; $fh = opendir($dirstr); while (false !== ($filename = readdir($fh))) { array_push($files, $filename); } closedir($fh); return $files; } PS I'm on my windows apache server but the forward slash seems to work in php that keeps it portable. I tried it both ways. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] unexpected include parse error
Paul Furman wrote: PS I'm on my windows apache server but the forward slash seems to work OK actually, it was the back slash that was causing problems, it only works with a forward slash! but... I've still got the include error: ??? Parse error, unexpected T_INCLUDE #call $dirstr= ./ include 'scandir.php'; error here scandir('$dirstr'); #function function scandir($dirstr) { $files = array(); $fh = opendir($dirstr); while (false !== ($filename = readdir($fh))) { array_push($files, $filename); } closedir($fh); return $files; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] unexpected include parse error
I've noticed in both of your posts that you aren't terminating the line before the include with a ; That would probably help. FYI... If you use / then you don't have to escape it like // only the \. Also, instead of .\\ you can use '.\' -Shawn Paul Furman [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] David Obrien wrote: the \ has to be slashed .\\; Ah great, thanks! that fixes most of the errors. The following runs where I define the $dirstr in the function but if I try to define it in the page that calls the function, it still gives Parse error, unexpected T_INCLUDE in [#call] #call $dirstr= .// this is where I want to define the directory include 'scandir.php'; scandir('$dirstr'); #function function scandir($dirstr) { $files = array(); #$dirstr=.//; $fh = opendir($dirstr); while (false !== ($filename = readdir($fh))) { array_push($files, $filename); } closedir($fh); return $files; } PS I'm on my windows apache server but the forward slash seems to work in php that keeps it portable. I tried it both ways. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] unexpected include parse error
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. Final result: #call.php $dirstr= ./; include 'scandir.php'; scandir('$dirstr'); #scandir.php function scandir($dirstr) { global $dirstr; #I HAD TO ADD THIS LINE ALSO $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 '.\' Ah ha! that explains my confusion :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] unexpected include parse error
Hi Paul, Quoting Paul Furman [EMAIL PROTECTED]: ?php $dirstr= ./ probably because you are missing a ; at the end? include 'scandir.php'; scandir('$dirstr'); you should also change this to scandir($dirstr); ? parse error, unexpected T_INCLUDE in [the above file] if I comment out the $dirstr= ./ above that error goes away and the scandir.php include runs (that's a php5 function that needs to be defined manually in PHP 4.3.4) HTH R'twick This message was sent using IMP, the Internet Messaging Program. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php