PHP/String/String Case

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

Change String case to lower

<?
$mixed_case_word = "Lower Case and Upper Case";
$lowercase = strtolower($mixed_case_word);
print($lowercase);
?>



Change String case to Upper

<?
$mixed_case_word = "Lower Case and Upper Case";
$lowercase = strtoupper($mixed_case_word);
print($lowercase);
?>



Initial-capping words is a very common task

<?php
     $first_name = "jeremy";
     $last_name = "allen";
     $middle_init = "w";
   
     $first_name = ucfirst($first_name);
     $last_name = ucfirst($last_name);
     $middle_init = ucfirst($middle_init);
   
     print("$first_name $middle_init $last_name<br />");
   
     $name = "jeremy w allen";
     $name = ucwords($name);
   
     print($name . "<br />");
?>



Trimming Strings: chop

<html>
<head>
<title>Trim Functions</title>
</head>
<body>
<span>
<?php
     $TrailingSpaces = "Trailing Spaces             ";
     $Leadingspaces = "             Leading spaces";
     $TrailingAndLeadingSpaces = "            Trailing and Leading Spaces         ";
     $TabString = $HTTP_USER_AGENT . "  \n\n\n      \t\t \r\r";
   
     print("\"$TrailingSpaces\"" . "<br />");
     print("\"$Leadingspaces\"" . "<br />");
     print("\"$TrailingAndLeadingSpaces\"" . "<br />");
     print("\"$TabString\"" . "<br />");
   
     $TrailingSpaces = chop($TrailingSpaces);
     $Leadingspaces = ltrim($Leadingspaces);
     $TrailingAndLeadingSpaces = trim($TrailingAndLeadingSpaces);
     $TabString = trim($TabString);
   
     print("<br/>");
   
     print("\"$TrailingSpaces\"" . "<br />");
     print("\"$Leadingspaces\"" . "<br />");
     print("\"$TrailingAndLeadingSpaces\"" . "<br />");
     print("\"$TabString\"" . "<br />");
?>
</span>
</body>
</html>