phptutorials

PHP program to count the number of integers in a string!

In this post, we are going to write a program to count the number of integers in a string!. First, we will get the string from the user then we will iterate on each character then find the count of numbers/integers in the string.

Before that let’s write a PHP function which returns the count of integers in the string,

The above function receives a string as a parameter and it returns the number of integers in the string. Go through each and every line in the above function to understand how it works.

Now, let’s see how can we use the above function,

I have used Bootstrap for a clean and neat look in the above program. Otherwise, it is a simple HTML form that has a textbox and a submit button. After entering the submit button I am using the above PHP function (find_num_of_integers) to get the number of integers in the string. That’s it.

You can see the demo here,

demo

Related Posts

Leave a Reply