I'm looking for a way that I can extract the first letter of each word from an input field and place it into a variable.
Example: if the input field is "Stack-Overflow Questions Tags Users"
then the output for the variable should be something like "SOQTU"
An abbreviation is a shortened form of a word or phrase; abbreviations of phrases are often composed of the first letter of each word of the phrase (i.e., acronym). To maximize clarity, use abbreviations sparingly. Also consider readers' familiarity with the abbreviation before using it.
An acronym is a pronounceable word formed from the first letter (or first few letters) of each word in a phrase or title.
$s = 'Stack-Overflow Questions Tags Users';
echo preg_replace('/\b(\w)|./', '$1', $s);
the same as codaddict's but shorter
u
modifier to regex: preg_replace('...../u',
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With