RE: Question about "shortening" a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: Steve Slater [mailto:slater@xxxxxxxxxxxxxxxxxxx] 
Sent: Saturday, March 12, 2005 5:29 PM

$name_array = explode(" ",$name);
$short_name = "$name_array[0] " . end($name_array);

> And a dozen other ways to do it I'm sure. I just finished a
> project with a mess of pattern matching so have regex on the brain. :-)

Hehe, I know the feeling

Ereg solution:

eregi("^([a-z] ).* ?([a-z])$", $name, $regs);
print "the name in short is $regs[1] $regs[2]";

But when dealing with names I think Your approach is better since there´s all kinds of chararcters from language to language, in Denmark ÆæØøÅå, in sweden äÄöÖ and so on. Of course I could do something like:
ereg("^(.+ ).* ?(.+)$", $name, $regs); // untested

-- 
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen 
Systemudvikler
Naverland 31

DK-2600 Glostrup
www.comx.dk 
Telefon: +45 70 25 74 74
Telefax: +45 70 25 73 74
E-mail: km@xxxxxxx

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux