Title Case

Title Case

Easy PHP PHP Strings 36 views
Explanation Complexity

Problem Statement

Capitalize the first letter of each word (words separated by spaces).

Input Format

One line string s.

Output Format

One line formatted.

Example

hello world from php
Hello World From Php

Constraints

|s|

Input / Output Format

Input Format
One line string s.
Output Format
One line formatted.
Constraints
|s|

Examples

Input:
hello world from php
Output:
Hello World From Php

Example Solution (Public)

PHP
<?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);
?>

Official Solution Code

<?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);
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.