Re: First Character In A String

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

 



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
> 

-- 
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