![]() |
Splitting Filenames
I have a directory that will hold word docs of meeting minutes. The word doc titles will be "Minutes 1-21-2009.doc". I would basically I want the names to be "Minutes - 1-21-2009". Right now my code looks like:
PHP Code:
|
It's a totally different approach to your script, but I think the following is much cleaner.
PHP Code:
|
...wow that is much cleaner. A few questions. I see you defined the extension explicitly, is there a way to catch if it is .docx? If the person upgrades.
|
For the glob, look into
GLOB_BRACE (on the glob manual page if you want to look for multiple discrete possibilities (such as .doc and .docx). For the $no_ext line, you could call pathinfo($basename, PATHINFO_FILENAME) which will cut off the extension whatever it is. |
I just looked, and you can use multiple astricks, so can't you just logically do:
PHP Code:
|
Sure, if you know the files in there will only ever be of a certain pattern which those match (for example, no ".doc.bak" files).
|
.doc.bak would be covered by the *.doc*. However it wouldn't be happy with stripping the ext.
|
| All times are GMT. The time now is 04:59 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0