Reply to Re: REGEXP problem

Your name:

Reply:


Posted by Erwin Moller on 10/12/06 15:40

frizzle wrote:

> Hi there,
>
> I'm not really experienced with regexpes etc. so that's why i come
> here.
> My script needs to parse the requested filename:
>
> Imagine the filename is index_en.html
> My output needs to be an array with the following:
> language => en (no underscore)
> file => index (no "_en")
> extension => html
>
> i created the following, but i don't know how to move on:
> preg_split( '/^[a-z0-9]*(_(en|_ru))?\.[a-z0-9]{2,4}$/', $filename );
>
> As you can see, the _en part can be left out (index.html) wich would
> have to return
> language => default
>
> I hope it's clear, cause i really need to get this going!
>
> Thanks.
>
> Frizzle.



Hi,

This part
(_(en|_ru))?
matches
_en or __ru or nothing (note the double _)

I doubt that is what you want.
I expect you mean:
(_(en|ru))?
which will match
_en
_ru
nothing

Unless you want to learn regexpr (which is fun), I think it is easier to use
explode:
$filename = "blabla_en.html";
$parts = explode(".",$filename);
$otherparts = explode("_",parts[0]);

$extension = $parts[1];
$file = $otherparts[0];
if (count($otherparts) == 1){
$language = "Default";
} else {
$language = $otherparts[1];
}

It is more code, but easier to understand. :-)

Regards,
Erwin Moller

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация