Announcement

Collapse
No announcement yet.

Convert name to initials with php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert name to initials with php

    I was surprised I couldn't find a function to do this, but I didn't look too hard as this quick and dirty version wasn't too difficult to write.

    Code:
    function getInitials($name){
    //split name using spaces
    $words=explode(" ",$name);
    $inits='';
    //loop through array extracting initial letters
    	foreach($words as $word){
    	$inits.=strtoupper(substr($word,0,1));
    	}
    return $inits;	
    }
    black-dog
    4theweb.co.uk Web stuff
    slipperyhill.co.uk Band
Working...
X