Unregistered User
|
OpenSourceCMS.com
Posted: 2012-03-21 03:32
Task: Display just the first name from the full name which is stored in the orfmat of LastName, FirstName MiddleName(optional) .Solution in PHP: Use of PHP strpos() and substr() functions.The syntax of these functions are:int strrpos ( string $haystack , string $needle [, int $offset] ) returns the position of needle in the haystack string starting from $offset position. Default value of $offset is 0.string substr ( string $string , int $start [, int $length ] ) returns a portion of the stringPHP code:$string= $fullname; // $fullname may have Kennedy, John F or Obama, Barack or $start=strpos($string,',')+2; // find the position of ,' and skip comma & spaceif (strpos($string,' ,$start)) { // case: there is a space after first name $length=strpos($string,' ,$start) $start; // get the length of first name} else { // case: no space after first name which means no middle name $length=strlen($string); // definitely greater or equal to length of firstmane}echo substr($string, $start, $length); // displays the first name, John or Barack or
|
evil9 Joined: March 12, 2007
Posts:
4
|
OpenSourceCMS.com
Posted: 2007-03-12 20:04
Hello..
I was browsing OSCMS and I did not find anything about OpenPHPnuke, so why dont you admins, just submit this great portal system to OSCMS so more and more people can be interested in it
Greetings from the middle of nowhere, Estonia
Heiko
LOL
|