Hi everyone,
let’s say I have an array filled with strings, such as:
$complete_words = array("blue suede shoes", "organic coffee", "sunset champagne cruise");
How do I go from the above array to the one below:
$abbreviated_words = array("bss", "oc", "scc");
In other words, find the first letter of every word in the strings.
Anyone know how to do this?
Thanks in advance!
try below code
$complete_words = array("blue suede shoes", "organic coffee", "sunset champagne cruise");
foreach ( $complete_words as $complete_word){
preg_match_all('/\\b\\w/', $complete_word, $match);
$abbreviated_words[] = implode("", $match[0]);
}
print_r('<pre>');print_r($abbreviated_words); print_r('</pre>');
Hi bhuthecoder,
thank you very much! :tup: It’s working great, much simpler than what I was trying to do.
I’ll have to read up on preg_match_all…
Thanks again for your assistance.