Home » Php » PHP: count amount of tabs at the beginning of a string

PHP: count amount of tabs at the beginning of a string

Posted by: admin July 12, 2020 Leave a comment

Questions:

Ok basically I have a string which could be anything but for the purposes of the question it is:

    Hello World 

As you can see it has been indented twice at the beginning and once at the end.
Is there a way to count the amount of tabs \t only at the beginning of the string with PHP?

Cheers Franky

How to&Answers:

Try this code, it does exactly what you ask:

strspn($string, "\t");

http://www.php.net/strspn