Jump to content

Recommended Posts

Hello,

 

I can't seem to get the GLOB_BRACE flag to work on windows (Apache2.2/PHP5.2.1). I've tried all of the following and nothing works (the variations are with / vs \\ and ' vs "):

 

<?php
print_r(glob("{C:/Apache2.2/htdocs/webapp/system/,C:/Apache2.2/htdocs/webapp/application/}config/log.php",GLOB_BRACE));
print_r(glob('{C:/Apache2.2/htdocs/webapp/system/,C:/Apache2.2/htdocs/webapp/application/}config/log.php',GLOB_BRACE));
print_r(glob("{C:\\Apache2.2\\htdocs\\webapp\\system\\,C:\\Apache2.2\\htdocs\\webapp\\application\\}config\\log.php",GLOB_BRACE));

print_r(glob("{C:/Apache2.2/htdocs/webapp/system,C:/Apache2.2/htdocs/webapp/application}/config/log.php",GLOB_BRACE));
print_r(glob('{C:/Apache2.2/htdocs/webapp/system,C:/Apache2.2/htdocs/webapp/application}/config/log.php',GLOB_BRACE));
print_r(glob("{C:\\Apache2.2\\htdocs\\webapp\\system,C:\\Apache2.2\\htdocs\\webapp\\application}\\config\\log.php",GLOB_BRACE));
?>

 

If I take out the GLOB_BRACE and specify the direct path, it does work:

<?php
print_r(glob("C:\\Apache2.2\\htdocs\\webapp\\application\\config\\log.php"));
print_r(glob("C:/Apache2.2/htdocs/webapp/application/config/log.php"));
print_r(glob('C:/Apache2.2/htdocs/webapp/application/config/log.php'));
?>

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/67459-glob-windows-and-glob_brace-issue/
Share on other sites

Why are you ending the brace before the end of the address? I am pretty sure that is why it isn't working.

 

The brace comes before the end because I'm looking for config/log.php and it could be in either one of those directories. There may be a log.php elsewhere, but I only want it if it exists in either of those 2 paths.

 

Hopefully that makes sense...

Well...because it's part of a method that takes in parameters to create the pattern:

 

glob($paths.$search.EXT, GLOB_BRACE + GLOB_NOSORT)

 

There probably are a lot of ways to work around the problem, but I found it interesting that in this case, the GLOB_BRACE flag seems to break things on windows. The same call works on linux (with different paths of course).

If it works on linux it isn't a PHP bug. I would guess that the reason it works on Linux and not Windows is because of the filesystems being different. I think Windows differentiates between files and directories more so than Linux. When you end the braces early, it probably looks for "config/log.php" as a file in that directory. In Windows it probably doesn't work because of how it discerns between the directory and file, but in Linux, it is probably just added to the address. Maybe not.

Well...it works in linux because linux does not use colons in the path names. The fact that glob can't handle windows paths in braces, seems to be to be a bug. But...I'll let them determine that ;)

 

Here's a link to the but report so you can see the test case I ran. If I moved the part of the string that contains the colon out of the braces, it works.

 

http://bugs.php.net/bug.php?id=42501

 

It will probably just require a different solution...but there definitely is an issue with GLOB_BRACE and colons.

 

Thanks for the help...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.