<?php
// If we have been sent a string then lets do stuff with it!
if(isset($_POST['num_str']))
{
// Store the origional number into the num string.
$num = $_POST['num_str'];
// Only repeat the adding process while $num is greater than 1.
while(strlen($num)>1)
{
$temp_num = 0;
// Go through all of the digits of the number and add them together.
for($i=0; $i<strlen($num); $i++)
$temp_num = $temp_num+substr($num, $i , 1);
// Replace the old number with the new one and then start again!
$num = $temp_num;
}
// Check that the number is not zero.
if($num != 0)
echo("The number is... ".$num."<br /><br />");
// Otherwise is can't be a numberic value
else
echo("Please enter a integer numeric value.<br /><br />");
}
// Otherwise return some
?>
Please Enter a Number.<br />
<form action="test.php" method="post">
<input type="text" name="num_str">
</form>