I would like to generate code which will recognize how many words we have in one string. If there is one word, to read first 3 characters but if there are more than one word, then to choose first character of each word.
I have tried code below, but this will recognize and take only first character of each word, so if there is only one word, it will take only one character.
<?php
$category = $title;
$category = explode(" ", $category);
foreach ($category as $value) {
echo $firstLetter = $value[0];
}
?>