PHP/String/trim — различия между версиями

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

Версия 10:37, 26 мая 2010

Checking the length of a trimmed string

 
<?
    $zipcode = trim("12344");
    $zip_length = strlen($zipcode);
    if ($zip_length != 5) {
        print "Please enter a ZIP code that is 5 characters long.";
    }
?>



Combining trim() and strlen()

 
if (strlen(trim($_POST["name"])) == 0) {
    $errors[] = "Your name is required.";
}



string trim ( string str [, string trim_chars] ) strips spaces, new lines, and tabs

 
<?
    $a = trim(" testing ");
    $b = trim(" testing ", " teng");
?>



trim() function removes all whitespace from both sides of string

 
Its syntax is: string trim (string string)
It will also remove the special characters "\n", "\r", "\t", "\v" and "\0".
<?
print ">".trim(" asdf ")."<";
?>