Calculating the length of a string is a useful feature of any language, in fact it’s one of the few pieces of functionality that has a consistently simple syntax across modern languages. You can calculate the length of a string as part of some server side user input validation or do so to determine if you should truncate a string and add ellipses to it. To calulcate the length of a string all you need to do is:

$string = 'This is my string, it’s kinda longish but not really.';
$length = strlen($string);

Not much to it! In a future post I’ll discuss truncating a string with ellipses :)