Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Compare String length in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.90k
    Comment on it

    Hello Reader's ,

    Today on My blog, You will learn how to compare string length in PHP.

    PHP provides strlen() function which compares two string length is equivalent to each other. The strlen() function returns the length of a string on success, and if the string is empty then it will return 0.

     

    <?php
    
    public function password_check($value)
    {
    	if(strlen($value) < 8)
    	{
    	 	
    		echo "The password is too short";
    
    	}elseif(strlen($value) > 10)
    	{
    		echo "The password is too long";
    
    	}else{
    
    		echo "The password is the proper length";
    
    	}
    }
    
    password_check("pass");
    password_check("password@123");
    password_check("password");

    In the above example, we are passing some parameter to password_check () function which checks the length of the string

    I hope this will help you. Please feel free to give us your feedback in comments.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: