0

Calculating the length of a string using PHP

The PHP function strlen can be used to find out how many characters are in a string. This is very useful for validating that there’s data in a string, and that a string isn’t larger than it should be.

$password="secret1";

if (strlen($password) <= 5)
{
echo("Passwords must be a least 5 characters long.");
}
else {
echo ("Password accepted.");
}
?>

Our Password Code will Return: Password accepted

Filed in: PHP Scripts

Recent Posts

Bookmark and Promote!

© 2012 Sumit Bansal. All rights reserved. XHTML / CSS Valid.