PHP ucwords() Function

PHP ucwords() Function is used to convert the first character of each word to uppercase in string. The ucwords() is an in-built function of PHP.

Syntax :

ucwords(string, separator) ;

Parameters ,

string : Required. It is string to convert the first character of each word to uppercase.

separator : Optional. It is the words separator characters. Default separator characters may be as below.

  • Space
  • \t - tab
  • \n - newline
  • \r - carriage return
  • \f - form feed
  • \v - vertical tab

The ucwords() Function returns string with first character of each word to uppercase.

Similar function of ucwords() :

    strtoupper() : It converts a whole string into uppercase.
    strtolower() : It converts a whole string into lowercase.
    lcfirst() : It converts only the first character of a string into lowercase.
    ucfirst() : It converts only the first character of a string into uppercase.

Let's see below example to understand php ucwords() Function in details.

Example :

<?php
$str= 'learn php ucwords function tutorial at aryatechno!';
$result1= ucwords($str);
echo "<br> ucwords function without separator : ".$result1;
$str= 'learn;php;ucwords;function;tutorial;at;aryatechno!';
$result2= ucwords($str);
echo "<br> ucwords function without separator : ".$result2;
$result3= ucwords($str, ";"); //ucwords with semicolon separator
echo "<br> ucwords function with semicolon separator : ".$result3;
?>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

96556