PHP/String/ucwords

Материал из Web эксперт
Перейти к: навигация, поиск

Controlling Case

 
<?php
  $submittedpass = "myPass";
  $newpass = strtolower ($submittedpass);
  
  echo $newpass . "<br />";
  
  $astring = "hello world";
  echo ucfirst ($astring) . "<br />"; 
  
  $astring = "hello world";
  echo ucwords ($astring); 
?>



Prettifying names with ucwords()

 
<?
print ucwords(strtolower("JOHN FRANKENHEIMER"));
?>



string ucwords ( string str ) converts the first letter of each word in the string to an uppercase character, leaving the others untouched.

 
<?
    $string = "i like to program in PHP";
    $a = strtoupper($string);
?>



submitted string lowercase with strtolower() before invoking ucwords():

 
<?php
$full_name = "tHis IS a tESt";
$full_name =  ucwords( strtolower($full_name) );
print $full_name; 
?>



ucwords() function capitalizes the first letter of each word in a string.

 
Its syntax is: string ucwords (string string)
<?
$sentence = "cooking and programming";
$sentence = ucwords($sentence);
print $sentence;
?>



ucwords() makes the first letter of every word in a string uppercase.

 
<?php
$full_name = "this is a test";
$full_name = ucwords ( $full_name );
print $full_name; 
?>



ucwords.php

 
<?php
   $title = "asdf asdf asdf!";
   echo ucwords($title);
?>