Thread: split 4 digit number into four variables

1. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2000
Posts
12
Rep Power
0
I've gone as far as I can and need serious help !
Here are the calculations I need to perform on a birth date.

Male
add together the last two digits of the \$year. If result is 10 or more, add the two digits together to reduce them to a single digit. Substract from 10. If answer is 5 use the digit 2. (if 5 ==2)

If \$year is 2000 or more subtract 9 (instead of 10)

Female
add together the last two digits of the \$year. If result is 10 or more, add the two digits together to reduce them to a single digit then add 5. If the result is 10 or more, add the two digits and reduce them to a single number.
If the answer is 5, use the digit 8 (if 5 == 8).

**********
input.html
<form method="post" action="lucky.php">
<input type=text value="" name="name">
<input type=text value="" name="gender">
<input type=text value="" name="byear">
<input type="submit" value="submit" name="button">

lucky.php
<?php
if (\$gender == "male") {
(\$byear ) // need to split last 2 digits into 2 variables \$last1, \$last2
(\$last1 + \$last2 = \$two)
if (\$two > 9) // need to split \$two into 2 variables, \$first, \$second
(\$first + \$second = \$third)
if (\$byear > 1999)
(9 - \$third = \$md)
else (10 - \$third = \$md)
}
if (\$md == 5) { // if \$md equals 5
(\$md == 2) ; // \$md equals 2
}
}

if (\$gender == "female") {
(\$byear ) //
(\$last1 + \$last2 = \$two)
if (\$two > 9) // need to split into two variables, \$first, \$second
(\$first + \$second = \$third)
if (\$byear > 1999)
(6 + \$third = \$fd)
else (5 + \$third = \$fd)
if (\$two > 9) // split into two variables again, \$first2, \$second2
(\$first2 + \$second2 = \$third)
}
if (\$fd == 5) {
(\$fd == 8 );
}
}

If (\$gender == \$md) {
echo "Dear \$name";
echo "\$md";
else
echo "Dear \$name";
echo "\$fd";
}
}
?>
2. Hi,

use substr() function for splitting your values.

i am writing a small exmple here.

eg:

\$byear="2000";

\$last1 =substr(\$byear,0,2);
# substr(string ,starting postion,length)
#returns 20.

\$last2 =substr(\$byear,2,2);

#this returns 00.

Now you can do the rest of the calculations very easily...