Home » PHP

PHP ucwords() Function with Example

PHP ucwords() Function: Here, we are going to learn about the ucwords() function with example in PHP.
Submitted by IncludeHelp, on February 06, 2019

PHP ucwords() Function

ucwords() function is a string function in PHP and it is used to converts the first characters in uppercase of all words in a string.

Syntax:

    ucwords(string);

It accepts the string and returns the new string with first character of the words in uppercase.

Examples:

    Input: "hello world how are you?"
    Output: "Hello World How Are You?"

    Input: "hello123"
    Output: "Hello123"

PHP code:

<?php
	$str = "hello world how are you?";
	echo (ucwords($str) . "\n");

	$str = "HELLO world how are you?";
	echo (ucwords($str) . "\n");	

	$str = "hello123 123hello";
	echo (ucwords($str) . "\n");		
?>

Output

Hello World How Are You?
HELLO World How Are You?
Hello123 123hello





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.