How to get String Length in PHP ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we learn how to find the length of the string in PHP. Approach: This task can be done by using the built-in function strlen() in PHP. This method is used to return the length of the string. It returns a numeric value that represents the length of the given string. Syntax: strlen($string) Example 1: PHP <?php // PHP program to count all // characters in a string $str = "GeeksforGeekslover"; // Using strlen() function to // get the length of string $len = strlen($str); // Printing the result echo $len; ?> Output: 18 Example 2: Below code demonstrates the use of strlen() function in PHP where the string has special characters and escape sequences. PHP <?php // PHP program to find the length of // a given string which has special // characters $str = "\n LuckyGeeks ;"; // Here '\n' has been counted as 1 echo strlen($str); ?> Output: 14 Create Quiz Comment M manaschhabra2 Follow 0 Improve M manaschhabra2 Follow 0 Improve Article Tags : Web Technologies PHP PHP Programs PHP-function PHP-Questions +1 More Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like