黃聖琪 黃聖琪 - 1 year ago 90
PHP Question

PHP glob can't read tmp

I am using wamp in win7, and I try to read c:\wamp\tmp by glob with php, but the result is an empty array

print_r(glob("C:\wamp\tmp\*"));


I can see any folder in
c:\wamp
except
c:\wamp\tmp
, and I make sure that folders has the same setting about read write...

Answer Source

\t is an escape sequence that means the Tab character. You have several ways to deal with it:

  1. Escape it with another backslash.

    print_r(glob("C:\wamp\\tmp\*"));
    
  2. Use single quotes instead of double quotes, since escape sequences aren't processed in single quotes.

    print_r(glob('C:\wamp\tmp\*'));
    
  3. Use forward slashes instead of backslashes, since Windows allows either as a directory separator.

    print_r(glob("C:/wamp/tmp/*"));