Title Case
PHP
Easy
5 views
Problem Description
Capitalize the first letter of each word (words separated by spaces).
Input Format
One line string s.
Output Format
One line formatted.
Sample Test Case
Input:
hello world from php
Output:
Hello World From Php
Official Solution
<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$parts=preg_split('/\\s+/', trim($inputText));
$output=[];
foreach($parts as $w){
$w=strtolower($w);
if($w===''){ continue; }
$output[] = strtoupper($w[0]).substr($w,1);
}
echo implode(' ',$output);
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!