PHP/String/strlen
Содержание
Calculating the length of a string
<source lang="html4strict">
<?php $password="password"; if (strlen($password) <= 5){
echo("Passwords must be at least 5 characters long.");
} else {
echo ("Password accepted.");
} ?>
</source>
Checking String Length
<source lang="html4strict">
<?php
define ("MAXLENGTH", 10); if (strlen ("Hello World!") > MAXLENGTH){ echo "The field you have entered can only be " . MAXLENGTH . " characters in length."; } else { //Insert the field into the database. }
?>
</source>
Checking String Length: int strlen ( string string )
<source lang="html4strict">
<?php define ("MAXLENGTH", 10); if (strlen ("Hello World!") > MAXLENGTH){
echo "The field you have entered can be only " . MAXLENGTH . " characters in length.";
} ?>
</source>
Concisely checking the length of a trimmed string
<source lang="html4strict">
<? if (strlen(trim("12345")) != 5) {
print "Please enter a ZIP code that is 5 characters long.";
} ?>
</source>
int strlen ( string str ) returns the number of characters in it:
<source lang="html4strict">
<?
print strlen("Foo") . "\n"; // 3 print strlen("Goodbye, Perl!") . "\n"; // 14
?>
</source>
strlen.php
<source lang="html4strict">
<?php
$pswd = "secretpswd"; if (strlen($string) < 10) echo "Password is too short!";
?>
</source>