Re: First Character In A String

From: Date: Sun, 21 Jan 2007 15:02:44 +0000
Subject: Re: First Character In A String
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-247507@lists.php.net to get a copy of this message
Christopher Deeley wrote: > Can anyone tell me if there is a function to return the first letter in a > string, such as: > > $surname="SMITH"; > $forename="ALAN"; > > Is there a function which I can use to make $forename "A", so I can display > it as A SMITH? another alternative to the other answers you have had, this alternative introduces you to the 'String access and modification by character' functionality as described here: http://nl2.php.net/manual/en/language.types.string.php <?php $initial = (is_string($forename) && strlen($forename) > 0) ? $forename[0] : '' ; echo trim($initial.' '.$surname); > > Thank You In Advance >

« previous php.general (#247507) next »