How would I get the first letter of each word for a given string?
$string = "Community College District";
$result = "CCD";
I found the javascript method but wasn’t sure how to convert it to php.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
explode()on the spaces, then you use an appropriate substring method to access the first character of each word.If you have an expectation that multiple spaces may separate words, switch instead to
preg_split()Or if characters other than whitespace delimit words (
-,_) for example, usepreg_split()as well: