Count The Length Of The String Using The Php Strlen() Function

The string data is an array of characters, and the length of the string data in PHP can be counted by using the strlen() function. It counts the length of a string that may contain alphabetic characters, numeric characters, special characters, và whitespaces. It counts the number of bytes for UTF8 encoded data. Different uses of the strlen() function in PHP have been shown in this tutorial.

Bạn đang xem: Count the length of the string using the php strlen() function

Syntax:The syntax of the strlen() function is given below.

strlen(string $string): int

It takes a string value as the mandatory argument, & this function will return the length of the string value.

Xem thêm: 10+ Các Mẫu Cắm Hoa Hồng Đẹp, Hướng Dẫn Cách Cắm Hoa Hồng Đơn Giản

Example-1: Counting the length of different data

Create the PHP file with the following script where the strlen() function has been applied for the string data, number data, and Boolean data.


//Declare a string variable $text = "Learn PHP Programming"; //Declare a number variable $number = 35000; //Declare a boolean value $bool = True; //Print the length of the string data echo "The length of string data is ".strlen($text); //Print the length of the number data echo "The length of number data is ".strlen($number); //Print the length of the Boolean data echo "The length of boolean data is ".strlen($bool);?>

Output:

The following đầu ra will appear after executing the above script. In the output, the total number of characters returned for the string data, the total number of digits returned for the number data, & 1 returned for the true value.

*
*
*
*
*
*
*
*
*

Fahmida Yesmin

I am a trainer of website programming courses. I like to write article or tutorial on various IT topics. I have a YouTube channel where many types of tutorials based on Ubuntu, Windows, Word, Excel, WordPress, Magento, Laravel etc. Are published: Tutorials4u Help.


View all posts
RELATED LINUX HINT POSTS

Linux Hint LLC, 1309 S Mary Ave Suite 210, Sunnyvale, CA 94087 Privacy Policy and Terms of Use