Sir I have these codes

$string = '  ab';
echo (strlen($string))."<br>"; // returns 4

$count = mb_strlen($string);
echo $count."<br/>"; // returns 4

$length = count(str_split($string));
echo $length."<br/>";// returns 4

All above method return 4

But I need 2 because there are TWO white spaces in the beginning of $string
So there are only two characters in $string.
How to count charcters without white spaces?

strlen(trim($string))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.