Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.erje.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Allodoxaphobia Newsgroups: comp.lang.php Subject: Re: use of substring in php Date: 21 Jun 2011 12:36:54 GMT Lines: 26 Message-ID: References: <27917623-6bef-416e-8ce3-856e9dd20bd9@v10g2000yqn.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net BH4kWE473xsUz939iFWCPwl4kKsCUU3z6ndRVN+sc5YH1sezk9 Cancel-Lock: sha1:OiOIDa6/9bo1a8eak2w200DoY8Q= User-Agent: slrn/0.9.9p1 (FreeBSD) Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:2273 On Mon, 20 Jun 2011 20:40:40 -0400, Bill B wrote: > On 6/20/2011 5:19 PM, Co wrote: >> >> I want to cut down the name of the user to 10 characters so it will >> fit to the picture of the user. >> At this moment I use $firstnameCut = substr($firstname, 0, 10); >> However sometimes the name is like: >> >> Johannes Paul. >> with my code it will show: Johannes P >> >> How can I change this so if the second or third name doesn't fit >> within the 10 characters >> it will not be shown at all? > > This is not a PHP answer per se. Give some though to using the first X > characters from the first name and the first Y characters from the last > name. It may resolve some of your dilemma. > It has a favorable side > effect of producing a decently unique set of characters (most of the time). And, an 'interesting' side effect of sometimes producing fairly vulgar character strings... Jonesy