Get PHP String Length

To Get PHP String Length we can use strlen in PHP, what it can do is it will counts number of characters for give string, word or paragraph. And output will be always an integer because that will be a number. It takes only one argument, that is string or a variable. String Length function in PHP, it will counts white spaces also. For example if you have a string to count number of characters then it will count white spaces, special characters and everything.

Syntax for PHP String Length

$output = strlen($string)

$output will be an integer because this is string length, and $string will be a string, word or paragraph.

Note: $string argument is mandatory.

If the string is empty $output will be zero(0), or it will return an integer value after execution if it’s correct string.

PHP String Length – Sample code Snippets

Simple PHP String Length code snippet with String, and output is 12.

echo strlen("Hello world!");

Passing this string as a variable to strlen PHP function.

$string = "Hello world!";
echo strlen($string);

If you want to learn more about strlen function, you can get information at php.net.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe