Which of the following is the use of strlen () function in php?
View Discussion Show Improve Article Save Article View Discussion Improve Article Save Article In this article, we will see how to get the length of the string using strlen() function in PHP, along with understanding its implementation through the examples. The strlen() is a built-in function in PHP which returns the length of a given string. It takes a string as a parameter and returns its length. It calculates the length of the string including all the whitespaces and special characters. Syntax: strlen($string); Parameters: The strlen() function accepts only one parameter $string which is mandatory. This parameter represents the string whose length is needed to be returned. Return Value: The function returns the length of the $string including all the whitespaces and special characters. Below programs illustrate the strlen() function in PHP: Example 1: The below example demonstrates the use of the strlen() function in PHP. PHP
Output: 13 Example 2: This example demonstrates the use of the strlen() function where the string has special characters and escape sequences. PHP
Output: 25 Reference: http://php.net/manual/en/function.strlen.php PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples. The strlen() function is used to get the string length. It returns the length of the string on success. If the string is empty, 0 is returned. Syntaxstrlen(str) Parameters
ReturnThe strlen() function returns the length of the string on success. If the string is empty, 0 is returned. ExampleThe following is an example − Live Demo OutputThe following is the output − 10
Updated on 26-Dec-2019 09:24:59
(PHP 4, PHP 5, PHP 7, PHP 8) strlen — Get string length Descriptionstrlen(string Parametersstring The string being measured for length. Return Values The length of the ExamplesExample #1 A strlen() example
Notes
See Also
rm dot nasir at hotmail dot com ¶ 6 years ago
chernyshevsky at hotmail dot com ¶ 18 years ago
joeri at sebrechts dot net ¶ 6 years ago
jasonrohrer at fastmail dot fm ¶ 9 years ago
vcardillo at gmail dot com ¶ 10 years ago
"Length: " . strlen($foo) . " basil at gohar dot us ¶ 12 years ago
= array('one', 'two', 'three'); John ¶ 5 years ago
= 100000000; // 100 million What is the use of strlen () function in PHP?The strlen() is a built-in function in PHP which returns the length of a given string. It takes a string as a parameter and returns its length. It calculates the length of the string including all the whitespaces and special characters.
What is the use of strlen () and strpos () functions in PHP?PHP String Functions. What is the use of strpos () function in PHP?strpos in PHP is a built-in function. Its use is to find the first occurrence of a substring in a string or a string inside another string. The function returns an integer value which is the index of the first occurrence of the string.
What is the meaning of strlen () function?The strlen() function calculates the length of a given string. The strlen() function takes a string as an argument and returns its length. The returned value is of type size_t (an unsigned integer type). It is defined in the
|