$str_len = strlen("foobar");
// -> 6
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.