How to find string length in PHP

  209 views   3 months ago PHP

Use the PHP strlen() function

You can simply use the PHP strlen() function to get the length of a string. The strlen() function return the length of the string on success, and 0 if the string is empty.

Let's take a look at the following example to understand how it actually works:

<?php
$str1 = 'Hello world!';
echo strlen($str1); // Outputs: 12
echo "<br>";
 
$str2 = ' Hello    world! ';
echo strlen($str2); // Outputs: 17
?>

i hope you like this one.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com

Related Articles