By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

Shorten this line?

P: n/a
Hi,

Is there a way to shorten this line

if ((ereg(".jpg",$filename))||(ereg(".eps",$filename) )||(ereg(".tif",
$filename))||(ereg(".tiff",$filename))||(ereg(".jp eg",$filename))||
(ereg(".ai",$filename))) {

I've tried ereg(array("1","2" etc),$filename) but it won't work. A bit
of context - I'm trying to filter files of certain types.

Thanks

A

May 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"UKuser" <sp********@yahoo.co.ukwrote in message
news:11**********************@q23g2000hsg.googlegr oups.com...
Hi,

Is there a way to shorten this line

if ((ereg(".jpg",$filename))||(ereg(".eps",$filename) )||(ereg(".tif",
$filename))||(ereg(".tiff",$filename))||(ereg(".jp eg",$filename))||
(ereg(".ai",$filename))) {

if(preg_match('#.+\.(jpg|jpeg|eps|tif|tiff|ai)$#', $filename)){

--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
May 16 '07 #2

P: n/a
On 16 May, 09:52, "Rami Elomaa" <rami.elo...@gmail.comwrote:
"UKuser" <spiderc...@yahoo.co.ukwrote in message

news:11**********************@q23g2000hsg.googlegr oups.com...
Hi,
Is there a way to shorten this line
if ((ereg(".jpg",$filename))||(ereg(".eps",$filename) )||(ereg(".tif",
$filename))||(ereg(".tiff",$filename))||(ereg(".jp eg",$filename))||
(ereg(".ai",$filename))) {

if(preg_match('#.+\.(jpg|jpeg|eps|tif|tiff|ai)$#', $filename)){

--
Rami.Elo...@gmail.com

"Good tea. Nice house." -- Worf
Thanks for that!

A

May 16 '07 #3

P: n/a
On May 16, 10:05 am, UKuser <spiderc...@yahoo.co.ukwrote:
On 16 May, 09:52, "Rami Elomaa" <rami.elo...@gmail.comwrote:
"UKuser" <spiderc...@yahoo.co.ukwrote in message
news:11**********************@q23g2000hsg.googlegr oups.com...
Hi,
Is there a way to shorten this line
if ((ereg(".jpg",$filename))||(ereg(".eps",$filename) )||(ereg(".tif",
$filename))||(ereg(".tiff",$filename))||(ereg(".jp eg",$filename))||
(ereg(".ai",$filename))) {
if(preg_match('#.+\.(jpg|jpeg|eps|tif|tiff|ai)$#', $filename)){
--
Rami.Elo...@gmail.com
"Good tea. Nice house." -- Worf

Thanks for that!

A
you can still shorten it a teeny bit more, by
\.(jpe?g|eps|tiff?|ai)$
instead of
..+\.(jpg|jpeg|eps|tif|tiff|ai)$
buy hey who cares right

May 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.