(Palindromes) A palindrome is a sequence of characters that reads the same backward as
forward.
For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and
11611.
Try this code. I hope you will learn from it.
<?PHP
$inputs = array();
if (isset($_POST['submit'])) { //to check if the form was submitted
$value = isset($_POST['input0'])? $_POST['input0'] : null;
for($count = 1; $value != null; $count++){
array_push($inputs, $value);
$value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;
}
}
var_dump($inputs);
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<!-- to take multiple inputs copy the below line and change name="input" attribute -->
Enter input 1: <input type="text" name="input0" value="" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
$dig = $inputs[0];
/*Now I need to get Mod 5th times from remaining value*/
$dig5 = ($dig % 10); //as mod of 10201 is 1 : $dig5 is Digit 5
$inputs[5] = $dig5; //1 is saved in 5th index
$dig4 = ($dig / 10); //value like 1020.1 : $dig4 is Digit 4
$dig4v = floor($dig4); //It will make 1020 : $dig4v is Digit 4th Value
$dig4vi = ($dig4v % 10); // as Mode of 1020 is 0 : $dig4vi is Digit 4th value index
$inputs[4] = $dig4vi; //0 is saved in 4th index
$dig3 = ($dig4v / 10); //value like 102.0 : $dig3 is Digit 3
$dig3v = floor($dig3); //It will make 102 : $dig3v is Digit 3rd Value
$dig3vi =($dig3v % 10); // as Mode of 102 is 2 : $dig3vi is Digit 3rd value index
$inputs[3] = $dig3vi; //2 is saved in 3rd index
$dig2 = ($dig3v / 10); //value like 10.2 : $dig2 is Digit 2
$dig2v = floor($dig2); //It will make 10 : $dig2v is Digit 2nd Value
$dig2vi = ($dig2v % 10); // as Mode of 10 is 0 : $dig2vi is Digit 2nd value index
$inputs[2] = $dig2vi; //0 is saved in 2rd index
$dig1 = ($dig2v / 10); //value like 1.0 : $dig1 is Digit 1
$dig1v = floor($dig1); //It will make 1 : $dig1v is Digit 1st Value
$inputs[1] = $dig1v; //1 is saved in 1st index
if (($inputs[0]>=10000)&&($inputs[0]<=99999))
{
if(($inputs[1]==$inputs[5])&&($inputs[2]==$inputs[4]))
{
echo "{$inputs[0]} is a palindrome number. <br />";
}
elseif(($inputs[1]!=$inputs[5])||($inputs[2]!=$inputs[4]))
{
echo "{$inputs[0]} is not a palindrome number. <br />";
}
}
else
{
echo "Try Again : Enter 5 Digit Number. :(";
}
?>
Post a Comment
Give your reviews about this blog. Leave your comments. What do you think about this post?
Comments Guidelines:
1) I love to read comments, but please avoid spam.
2) Like this blog, share your insights, and spread the word.
3) You can use basic HTML/xHTML tags.
4) All comments are DoFollow—please use the section professionally.
5) Kindly mention your name or brand below your comment.
6) Constructive suggestions for improvement are always welcome.
Thanks for visiting Samee Articles.
========================================
Best Regards,
Samee U. Feroz