Calculate length of a string using strlen() function in php

The strlen() function in PHP is used to calculate the length of a string. It takes a string as an argument and returns the number of characters in that string.

   $str_len = strlen("foobar");

   echo $str_len;
   // -> 6
Output will be : 7

To get the length of a string strlen() function is used in PHP. In the code, we have passed a string which has the value - 'foo bar'. It will return '7' as an output as the string length. 

Was this helpful?