Method 1: Using strlen() Method: The strlen() method is used to get the length of a given string str. Length of the string including all the white spaces and special characters in this method.
Syntax:
strlen( $string )
<?php
//php program to count all characters in s string
$str="company website";
$leng=strlen($str);
//printing the result
echo $leng;
?>
Method 2: Using mb_strlen() Method: The mb_strlen() method is used to return the number of characters in a string having character encoding. A multi-byte character is counted as
Syntax:mb_strlen($str, $encoding);
sudo apt install php7.0-mbstring
<?php
//php program to count all characters in a string
$str="software company";
//mb_strlen function to get the length of string
$len=mb_strlen($str);
echo $len;
?>
int iconv_strlen( string $str, string $charset = ini_get("iconv.internal_encoding"))
<?php
// PHP program to count number
// of characters in a string
$str = " IT tech company ";
// Using iconv_strlen() function
// to get the length of string
$len = iconv_strlen($str);
// Printing the result
echo $len;
?>
int grapheme_strlen(string $input)
Example:
<?php
// PHP program to count number
// of characters in a string
$str = " Bajarangi software company ";
// Using grapheme_strlen() function
// to get the length of string
$len = grapheme_strlen($str);
// printing the result
echo $len;
?>