SnapShooter Backups Server, Database, Application and Laravel Backups - Get fully protected with SnapShooter

How to make all words start with a capital letter in a sentence using PHP

In this tutorial, we introduce a code snippet. Its function is to make all words start with a capital letter in a sentence. If there is any non-first capital letter, it will convert them to lowercase.

Function

Make all words start with a capital letter in a sentence.

Snippet

<?php
ucwords(strtolower($string));
?>

This snippet is a combination of two PHP native functions:

  1. strtolower(): this function will converted all alphabetic characters to lowercase.
  2. ucwords(): this function will converted the first character of each word in a string capitalized.

The end

Hopefully this simple tip helped you with your development. If you like our post, please follow us on Twitter and help spread the word. We need your support to continue. If you have questions or find our mistakes in above tutorial, do leave a comment below to let us know