How to count the length of string in PHP

by Lalita 04-Aug-19

0 172


To count the length of string or to check the length of string there is an inbuilt function used in PHP i.e strlen function (strlen() function). One parameter is used and it is mandatory for this function. It returns the value if true.

Example:

<?php 
  echo strlen('Hello! Who Are You?');
?>

Output: 19


You can also check the true condition.

Example:

<?php
 $get_string= strlen('Hello! Who Are You?');
  if($get_string<20)
  {
   echo "Length is less than 20.";
  }
  else{
	echo "Length is greater than 20.";
      }
?>

Output: Length is less than 20.


Share:


Comments

    Waiting for your comments

Leave a Reply