You are here: RE: [PHP] Question about "shortening" a string « PHP « IT news, forums, messages
RE: [PHP] Question about "shortening" a string

Posted by Kim Madsen on 03/16/05 14:24

-----Original Message-----
From: Steve Slater [mailto:slater@handsonsecurity.com]
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@comx.dk

 

Navigation:

[Reply to this 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

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