64. PHP Program to find the number of digits of a given number.
How does this program work?
- This program is used to find the number of digits of a given number using PHP.
- The integer entered by the user is stored in variable n.
- Here we are using while loop and this loop will be iterated upto n not equal to zero, once n will be zero the loop is terminated.
Here is the code
<html>
<head>
<title>PHP Program To find the number of digits of a given number</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num1" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['num1'];
$n1 = $n;
$totalDigits = 0;
while($n != 0)
{
$n = round($n/10);
$totalDigits ++;
}
echo "Total no.of digits in the given number $n1 is " .$totalDigits;
return 0;
}
?>
</body>
</html>