Re: Re: Question about "shortening" a string

From: Date: Sat, 12 Mar 2005 01:53:08 +0000
Subject: Re: Re: Question about "shortening" a string
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-210575@lists.php.net to get a copy of this message
Mário Gamito wrote:
Hi Sokolewicz, Thanks a lot. It just working really fine :) M. Sokolewicz wrote: Mário Gamito wrote:
For example, if i fill the form with "Mário Augusto Machado dos
Reis Gamito", i want to change this string to only "Mário Gamito".
The total number of names is not fix. Could be 3, 4, 5, 6,... Does anyone knows how to do this ?
<?php $parts = explode(' ', $fullName); $shortenedName = $parts[0].' '.$parts[count($parts)-1]; ?> This might solve one problem. What about people who have names like 'Pablo Ricardo del Rey' where you can't simply pick first and last because their last name really is 'del Rey'. Or 'von Braun', or ...you get the idea.
-- H | I haven't lost my mind; it's backed up on tape somewhere. +-------------------------------------------------------------------- Ashley M. Kirchner <mailto:ashley@pcraft.com> . 303.442.6410 x130 IT Director / SysAdmin / WebSmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com ..... . . . Boulder, CO 80303, U.S.A.

« previous php.general (#210575) next »