php capitalize first letter of each word code example

Example 1: php uppercase

//string to all uppercase
$string = "String with Mixed use of Uppercase and Lowercase";
//php string to uppercase
$string = strtoupper($string);
// = "STRING WITH MIXED USE OF UPPERCASE AND LOWERCASE"

Example 2: string first letter uppercase php

<?php
$foo = 'hello world!';
$foo = ucfirst($foo);             // Hello world!

$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

Example 3: php ucfirst all words

$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!

$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!

//With custom delimiter
$foo = 'hello|world!';
$bar = ucwords($foo);             // Hello|world!

$baz = ucwords($foo, "|");

Example 4: first character uppercase php

ucwords("hello world"); // Hello World
ucfirst("hello world"); // Hello world

Example 5: ucwords in php

<?php
/* Convert the first character of each word to uppercase: */
echo ucwords("hello samy, how are you ?");

//output : Hello Samy, How Are You ?
?>

Example 6: php uppercase each word

$upperCaseSentance=ucwords("i do not feel good");//I Do Not Feel Good

Tags:

Php Example