Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.
Hello Friends Today, through this tutorial, I will tell you How do you Use of the strlen() function using PHP, PHP 8, PHP 8.1, PHP 8.2, PHP 8.3 With Example. The `strlen()` function in PHP is used to get the length of a string. It returns the number of characters in a string, including spaces and special characters. This function is available in both PHP 8.1 and PHP 8.2.
Here’s how you can use it:
<?php // Original string $string = "Hello, World!"; // Get the length of the string $length = strlen($string); // Output the length of the string echo "The length of the string is: $length"; ?>
In this example, the `strlen()` function is applied to the original string `”Hello, World!”`. It returns the length of the string, which is then stored in the variable `$length`. Finally, the length of the string is echoed out.
The output will be:
The length of the string is: 13
You can use `strlen()` to perform various tasks in PHP, such as validating input length, manipulating strings, or iterating over characters in a string. It’s a fundamental function for string processing in PHP.