Categories: PHP

ucwords – PHP String Functions

Syntax :

ucwords ( string, seperator/delimiters );

Description :

ucwords() function will take string as input and converts first letter of every word in a string to uppercase letter, if that character is alphabetic. In general language, its name implies UC = Upper Case the words.


Parameter :

  • string – This is a Required parameter. This is a string on which function will be performed.
  • seperator/delimiters –  This is a Optional parameter. It contains the word separator characters. By default these characters are
    • space
    • \t : tab
    • \r : carriage return
    • \n : newline
    • \f : form feed
    • \v : vertical tab
Note : This function is binary-safe.

ChangeLog :

[table caption=”” width=”100%” colwidth=”50%|50%” colalign=”left|left”]
Version, Description
5.4.32 & 5.5.16, Added the delimiters parameter.

[/table]


Output :

This will return a changed string.


Related articles : strtolower(), strtoupper(), ucfirst(), lcfirst().


ucwords() – PHP Functions Example 1 :
<?php
$strExample = "An example of a ucwords() function.";
echo ucwords($strExample);
?>

In above example ,We have a string ‘An example of a ucwords() function’. Now this function will converts every first letter in a word to Uppercase. See below is the output of above code.

An Example Of A Ucwords() Function

ucwords() – PHP Functions Example 2 :
<?php
$strExample = "AN Example Of A ucwords() function WITH 789789.";
echo ucwords($strExample);
?>

In above example ,We have a string ‘AN Example Of A ucwords() function WITH 789789.’. Now this function will converts every first letter in a word to Uppercase, it will not do anything with numeric numbers. See below is the output of above code.

AN Example Of A Ucwords() Function WITH 789789.

ucwords() – PHP Functions Example 3 :

If you want to apply ucwords function on the basis of some separator. Use below example :

<?php
$strExample ="an example |of a ucwords() |function.";
echo ucwords($strExample,"|");
?>

Output will be like below:

An example |Of a ucwords() |Function.

jyoti rani

Recent Posts

What Is a Progressive Web App? Why Would You Need One?

App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…

1 year ago

7 Most Popular Paid Online Advertising Strategy

As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…

1 year ago

The Importance of User-Centered Design in Mobile App Development

Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…

1 year ago

Healthcare Mobile App Development: A Complete Guide for Founders

COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…

1 year ago

Exploring Diverse WordPress Theme Niches: A Comprehensive Guide

Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…

1 year ago

8 Awesome Blog Content Ideas for Movers to Skyrocket the SEO

For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…

1 year ago