|
 |
beginning_php thread: Concantenating "userfile_name" extensions
Message #1 by "Wayne Frisch" <wfrisch@b...> on Fri, 8 Feb 2002 08:16:04
|
|
currently I have a program which uploads a file to a directory and posts
the userfile_name in a table in Mysql.
I want to call the id of a row and take the variable userfile_name
and replace the extension to another.
Example;
example1.ps is listed in the Mysql database I want to change the filename
extension only however leave the suffix intact
example
original
example.ps
concantenated, renamed file
example.pdf
Message #2 by "Wayne Frisch" <wfrisch@b...> on Fri, 8 Feb 2002 08:38:18
|
|
I actually meant to say leave the prefix intact and change only the suffix
>currently I have a program which uploads a file to a directory and posts
> the userfile_name in a table in Mysql.
>
> I want to call the id of a row and take the variable userfile_name
> and replace the extension to another.
>
> Example;
>
> example1.ps is listed in the Mysql database I want to change the
filename
> extension only however leave the suffix intact
> example
>
> original
>
> example.ps
>
> concantenated, renamed file
>
> example.pdf
Message #3 by "Nikolai Devereaux" <yomama@U...> on Fri, 8 Feb 2002 08:58:07 -0800
|
|
This would require a simple regular expression search.
$new_filename = eregi_replace("^(.*\.)ps$", "\\1pdf", $filename);
I haven't tested it, so don't take my word for it.
If you're unfamiliar with the ereg functions, this basically says that
you'll match all the non-whitespace chars (.*) from the beginning of the
line (^) up until a period (\.), then take the string you matched (\\1) and
append a pdf to it. You will look in $filename, and return the new string,
which is stored in $new_filename.
hope this helps.
Hell, I hope this works!
take care,
nik
> -----Original Message-----
> From: Wayne Frisch [mailto:wfrisch@b...]
> Sent: Friday, February 08, 2002 8:38 AM
> To: beginning php
> Subject: [beginning_php] Re: Concantenating "userfile_name" extensions
>
>
> I actually meant to say leave the prefix intact and change only the suffix
>
>
>
>
> >currently I have a program which uploads a file to a directory and posts
> > the userfile_name in a table in Mysql.
> >
> > I want to call the id of a row and take the variable userfile_name
> > and replace the extension to another.
> >
> > Example;
> >
> > example1.ps is listed in the Mysql database I want to change the
> filename
> > extension only however leave the suffix intact
> > example
> >
> > original
> >
> > example.ps
> >
> > concantenated, renamed file
> >
> > example.pdf
>
> $subst('Email.Unsub').
|
 |