How to get String Length in PHP ?
Last Updated :
20 May, 2021
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
$str = "GeeksforGeekslover" ;
$len = strlen ( $str );
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
$str = "\n LuckyGeeks ;" ;
echo strlen ( $str );
?>
|
Output:
14
Share your thoughts in the comments
Please Login to comment...