Jump to content

PHP File System - The fnmatch() Function


iwato

Recommended Posts

QUESTION ONE:PART A: What is the difference between shell and regular expression syntax? For example, are their times when one is preferred over the other, even though both are applicable? Or, are they mutually exclusive? Can they used together?PART B: Is the regular expression syntax standard across platforms and applications? For example, can I depend on my knowledge of regular expression syntax in Javascript and ActionScript when working with PHP? PART C: How about shell syntax? Is it just as flexible?PART D: How does one go about learning shell syntax?QUESTION TWO: Why do the following two blocks of code both fail?BACKGROUNDOne was obtained from the W3 Schools website and one from the PHP website. Each set of code was run separately on a Mac OS 10.5.8 with PHP 5.0+. Research on the net reveals that the Mac OS is probably POSIX conformant. I have adjusted the code syntax so that it would at least process. Yeah, I know they are operationally identical, but the PHP website example is hopelessly flawed.W3 Schools

$txt = "My car is darkgrey...";if (fnmatch("*gr[ae]y",$txt))  {  echo "some form of gray ...";  }

PHP Website

$color = "My car is darkgrey...";if (fnmatch("*gr[ae]y", $color)) {  echo "some form of gray ...";}

Roddy

Link to comment
Share on other sites

A: They are two different pattern matching systems. Some things will use shell patterns, most will use regular expressions.B: There are several "flavours" of regular expressions (e.g. REG, EREG, PCRE), but they are mostly very similar, and so yes, you will find that your knowledge of regular expressions will serve you well in most applications.The PHP preg_ functions use PCRE no matter what system you are on (there is also EREG, soon to be removed).C: Well, not really. I believe it originated in the GNU project as a simpler form of pattern matching for files, but it doesn't have many uses outside that.D: Start here. It is really really simple (unlike regular expressions).TWO: Because you have text after "grey".P.S. POSIX compliance has nothing to do with how PHP processes regular expressions.

Link to comment
Share on other sites

POSIX compliance has nothing to do with how PHP processes regular expressions.
My search for shell expressions took me down a myriad of paths with a variety of outcomes that I did not understand very well. It is the reason that I finally surrendered and asked for help.By the way, I removed the extra characters in my code and everything worked fine. Perhaps the W3 School's entry for fnmatch() should be modified, as it is misleading in its present form.Also, thank you for the link to shell expressions. It was very helpful.Roddy
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...