Get the length of a string in PHP

This might be one of the easiest things you’ll ever do, in PHP to be precise. To get the length of a string in PHP you use the strlen() function. It takes a string as its argument and returns the length of the string, the amount of individual characters with spaces, tabs, line breaks, etc. included.

<?php

echo strlen('four');
# => 4

Easy peasy.

In case you want to check if a string is empty you could better use the empty() function. Which checks whether a variable is empty.

See Also

6 Non-Programming Books for Programmers