How to find string length in PHP

The PHP strlen() is used to get the length of a string. It also includes the white spaces inside the string.

Syntax:

strlen(string)

string – This parameter is required. It specifies the length of the string including all the special characters and whitespaces.

Example:

<?php
$str1 = 'Welcome to PHP Tutorial';
echo strlen($str1); // Outputs: 23

$str2 = ' Welcome to PHP Tutorial ';
echo strlen($str2); // Outputs: 28
?>

Praveen Kumar

I am a fullstack web developer with a passion for SEO, creating stunning websites, and organic marketing. I am a perfectionist.

Post navigation