PHP/String/String Case
Содержание
Change String case to lower
<source lang="html4strict">
<? $mixed_case_word = "Lower Case and Upper Case"; $lowercase = strtolower($mixed_case_word); print($lowercase); ?>
</source>
Change String case to Upper
<source lang="html4strict">
<? $mixed_case_word = "Lower Case and Upper Case"; $lowercase = strtoupper($mixed_case_word); print($lowercase); ?>
</source>
Initial-capping words is a very common task
<source lang="html4strict">
<?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
"); $name = "jeremy w allen"; $name = ucwords($name); print($name . "
");
?>
</source>
Trimming Strings: chop
<source lang="html4strict">
<html> <head> <title>Trim Functions</title> </head> <body> <?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\"" . "
"); print("\"$Leadingspaces\"" . "
"); print("\"$TrailingAndLeadingSpaces\"" . "
"); print("\"$TabString\"" . "
"); $TrailingSpaces = chop($TrailingSpaces); $Leadingspaces = ltrim($Leadingspaces); $TrailingAndLeadingSpaces = trim($TrailingAndLeadingSpaces); $TabString = trim($TabString); print("
"); print("\"$TrailingSpaces\"" . "
"); print("\"$Leadingspaces\"" . "
"); print("\"$TrailingAndLeadingSpaces\"" . "
"); print("\"$TabString\"" . "
");
?> </body> </html>
</source>