[thelist] get filename before the extension (php)

Mark Mckee lists at soddengecko.com
Thu Feb 1 14:57:25 CST 2007

Paul Bennett wrote:
> Hi Mark,
> Do you have control over the filenames? Can you guarantee that the filename won't have more than one full stop / period?
> If so then using explode('.', $filename);
> Will give you an array like:
> Array(
> 	0 => '/my/path/to/filename'
> 	1 => 'txt'
> )
> If there is more then one full stop / period, a regexp will be your best bet and my regexp kung-fu isn't too flash :)
> Also, it looks like your original system is appending the extra '.txt' to the filename without first checking if it already has the extension...
> Paul

that does look like what i am after. you will have to forgive me, i am 
not the greatest with php at all, but i do like to give it a go.

I have now noticed some glaring errors in my code.

a) when i put a " in the data field it returns this in the file \"

b) i cannot get line breaks to work. no matter how many carriage returns 
  there are, i always end up with a load of text jumbled up.

it looks like i am going to have to start again and rebuild the code. i 
will definitely try your code out once I have it fixed and will try to 
implement your suggestion about checking if the extension exists.

if there is anyone willing to take a peak at my code and give me some 
pointers i would be extremely greatful

thanks all.


More information about the thelist mailing list