WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to find string length in PHP

Topic: PHP / MySQLPrev|Next

Answer: Use the PHP strlen() function

You can simply use the PHP strlen() function to get the length of a string. The strlen() function return the length of the string on success, and 0 if the string is empty.

Let's take a look at the following example to understand how it actually works:

<?php
$str1 = 'Hello world!';
echo strlen($str1); // Outputs: 12
echo "<br>";
 
$str2 = ' Hello    world! ';
echo strlen($str2); // Outputs: 17
?>

Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties