How to get String Length in PHP ? Last Updated : 20 May, 2021 Summarize Comments Improve Suggest changes Share 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 Comment More infoAdvertise with us Next Article How to add a Character to String in PHP ? M manaschhabra2 Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-function PHP-Questions +1 More Similar Reads How to Copy String in PHP ? Copying a string is a basic operation that all the programming languages offer. In this article, we will explore different approaches to copying a string in PHP, including using the assignment operator, the strval() function, the substr() function and by implementing the strcpy() function.Table of C 3 min read How to add a Character to String in PHP ? Given two strings, the task is to add a Character to a String in PHP. The character can be added to a string in many ways in this article we will be using eight methods including the Concatenate Method, the String Interpolation Method, the str_pad() Method, Concatenation Assignment (.=) Operator, St 5 min read How to Get All Substrings of a Given String in PHP ? Extracting all possible substrings from a given string is a common task in text processing, pattern recognition, and various other applications in PHP programming. This operation involves generating every possible combination of characters present in the string, including both contiguous and non-con 3 min read How to Iterate Over Characters of a String in PHP ? This article will show you how to iterate over characters of string in PHP. It means how to loop through an array of characters in a string. There are two methods to iterate over the character of a string, these are:Table of ContentUsing str_split() function and foreach LoopUsing for LoopUsing mb_su 3 min read PHP Program to Print Even Length Words in a String This article will show you how to print even-length words in a string using PHP. Printing even-length words from a given string is a common task that can be approached in several ways. Table of ContentUsing explode() and foreach() FunctionsUsing array_filter() and strlen() FunctionsUsing preg_split( 3 min read How to get the last n characters of a PHP string? Write a PHP program to get last n characters of a given string. Examples: Input : $str = "GeeksforGeeks!" $n = 6 Output : Geeks! Input : $str = "GeeksforGeeks!" $n = 9 Output : forGeeks! Method 1: Tn this method, traverse the last N characters of the string and keep appending them in a new string. E 1 min read Like