PHP strlen() Function
In this chapter you will learn:
- Definition for PHP strlen() Function
- Syntax for PHP strlen() Function
- Parameter for PHP strlen() Function
- Return for PHP strlen() Function
- Example - Get the string length
Definition
The strlen() function takes a string and returns the number of characters in it.
Syntax
PHP strlen() Function has the following syntax.
int strlen ( string str )
Parameter
str
is the string value to check.
Return
PHP strlen() Function returns the length of a string.
Example
Get the string length
<?PHP
print strlen("Foo") . "\n";
print strlen("Hi from java2s.com!") . "\n";
?>
For multibyte strings we should be measured with mb_strlen()
.
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP strnatcasecmp() Function
- Syntax for PHP strnatcasecmp() Function
- Parameter for PHP strnatcasecmp() Function
- Return for PHP strnatcasecmp() Function
- Note for PHP strnatcasecmp() Function
- Example - Compare two strings using a "natural" algorithm (case-insensitive)
- Example - Difference between natural algorithm (strnatcmp) and regular computer string sorting algorithms (strcmp)
Home » PHP Tutorial » PHP String Functions