Re: Regular Expressions - A relatively simple search...
| From: | Mike Gifford | Date: | Mon, 10 Sep 2001 05:03:14 +0000 |
| Subject: | Re: Regular Expressions - A relatively simple search... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66663@lists.php.net to get a copy of this message | ||
Thanks..
_lallous wrote:
<? $str = "/home/mike/test.txt"; if (preg_match("/[^\.]+$/", $str, $matches)) $ext = $matches[0]; else $ext = "no extension"; echo "extension=$ext"; ?> "Mike Gifford" <mike@openconcept.on.ca> wrote in message news:3B97DF21.2030008@openconcept.on.ca...-- Mike Gifford, OpenConcept Consulting, http://openconcept.ca Offering everything your organization needs for an effective web site. Abolish Nuclear Weapons Now!: http://pgs.ca/petition/ It is a miracle that curiosity survives formal education. - A EinsteinHello, I'm trying to replace a couple of lines of code: $dotpos = 1 - (strlen($userfile_name) - strpos($userfile_name, '.')); $extension = substr($userfile_name, $dotpos); with a simpler regular expression: $extension = eregi_replace( "/.*", "", $userfile_name); However it isn't working.. What I'd like to do is to find the extension of a file name and place thatin a variable. So in'/home/mike/test.txt', I want to have the statement return 'txt' Any help would be appreciated.. Mike -- Mike Gifford, OpenConcept Consulting, http://openconcept.ca Offering everything your organization needs for an effective web site. Abolish Nuclear Weapons Now!: http://pgs.ca/petition/ It is a miracle that curiosity survives formal education. - A Einstein