(This question is not a duplicate of this.)
How can I capitalize the string llc
when found within another string, surrounded by word boundaries? In other words, I don't want to captilalize llc
if it's in the middle of another word, such as ballcap
, but only when it's by itself, either surrounded by spaces, end of string, etc. Such as my big company, llc
.
I have the following line of PHP that worked fine in PHP 5.6, to capitalize the string llc
whenever found within another string:
$foo = trim(preg_replace('/\bllc\b/ie', 'strtoupper("$0")', $str));
But in PHP 7.4 (and maybe all 7.x), that always returns empty string, regardless of what string is fed in for the value of $str
.
I have tried using preg_replace_callback
but can't seem to get the syntax right for my use case.
Example: big company, llc
should become big company, LLC
Any idea how I can get this working in 7.4?