.


Divya

strlen() function in php


The strlen() function is used to returns the length of a string in PHP.

Syntax

strlen(string)

Example

<!DOCTYPE html>
<html>
<body>
<?php
echo strlen("Students Tutorial");
?>
</body>
</html>

Real world Example

For know the length of a user password at the time of form input.

<!DOCTYPE html>
<html>
<body>
<?php
if(isset($_POST['save']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$count=strlen($password);
if ($count>=6){
echo "";
}
else {
echo "Password length at least 6";
}
}
?>
<form method="post" action="">
Name:<br>
<input type="text" name="name">
<br>
Email Id:<br>
<input type="email" name="email">
<br>Password:<br>
<input type="password" name="password">
<br><br>
<input type="submit" name="save" value="submit">
</form>
</body>
</html>


.