Q:

How to find string length in PHP

0

How to find string length in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to check whether a variable is set or not in P... >>
<< How to create a new line in PHP...