

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP program to find the number of characters in the string
To find the number of characters in the string, the PHP code is as follows −
Example
<?php $my_string = "Hi there, this is a sample "; $len = mb_strlen($my_string); print_r("The number of characters in the string is "); echo $len; ?>
Output
The number of characters in the string is 27
Above, a string is defined that has more than the required spaces in between −
$my_string = "Hi there, this is a sample ";
Next, the length of the string is computed using the ‘strlen’ function. This length is assigned to a variable. This will give the characters present in the string including the spaces as well −
$len = mb_strlen($my_string);
The length computed is then printed on the screen −
print_r("The number of characters in the string is "); echo $len;
- Related Questions & Answers
- PHP program to find the length of the last word in the string
- Python Program to Calculate the Number of Words and the Number of Characters Present in a String
- Java Program to Find the Duplicate Characters in a String
- How to find the number of characters in each row of a string column in R?
- C++ Program to Find the Number of Permutations of a Given String
- PHP program to remove non-alphanumeric characters from string
- Counting the number of redundant characters in a string - JavaScript
- Python Program to Count Number of Lowercase Characters in a String
- What MySQL INSERT() function returns if the number of characters to be removed exceeds the number of characters available in original string?
- How to count the number of repeated characters in a Golang String?
- Program to find length of concatenated string of unique characters in Python?
- How to find the number of occurrences of unique and repeated characters in a string vector in R?
- How to count the number characters in a Java string?
- Java Program to find duplicate characters in a String?
- Python Program to find mirror characters in a string
Advertisements