Title case a string containing one or more last names while handling names with apostrophes
In PHP, you can use the ucwords() function to convert a string to title case.
In PHP, you can use the ucwords() function to convert a string to title case. It natively handles apostrophes correctly, automatically capitalizing the letter that follows them. Here's an example:
Example of title case a string containing one or more last names while handling names with apostrophes in PHP
php— editable, runs on the server
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Learn object oriented PHP</div>
Note that ucwords() works reliably for standard ASCII names. If you are working with multibyte strings or need to handle apostrophes in other positions, consider using mb_convert_case($name, MB_CASE_TITLE, 'UTF-8') instead.