PHP String Length

Length is a property of a string. Through strlen function you can get the length of a string that means you can count the number of characters, of a particular string. If you want to count total characters of a string then you will have to pass your string as a parameter to strlen function which is built in PHP function. This will return you total number of characters of string. The example of strlen function is mentioned below: Code


<?php
  $StringVariable = "Hello All, this is a string example";
  // below mentioned statement shows you how to count total no. 
  // of characters of a string
  $totalCharacter = strlen($StringVariable);
  print($totalCharacter);
?>
In above mentioned example we have a string variable with the name of $StringVariable. Then in other statement we tried to get total number of characters of $StringVariable with the help of strlen function and store it to $totalCharacter variable then we print $totalCharacter variable.