|
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]
|