In this article I would like to share with you a sample program that I wrote in PHP that will accept a number and then it will check if the given number is a palindrome or not a palindrome. I called this program Palindrome of Numbers in PHP. For your information Palindrome means that when we read a word or number forward and backward it is the same for example of words that is palindrome in nature is RADAR, AMA, ANA and for numbers 141, 111, 212, 1441. I hope you will find my work useful in your learning PHP programming.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com. People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360.
Program Listing
<html>
<title> Palindrome of Numbers</title>
<style>
body {
font-size:20px;
font-family:arial;
color:blue;
}
label{
display: table-cell;
text-align: justify;
}
input {
display: table-cell;
}
div.row{
display:table-row;
}
</style>
<?php
error_reporting(0);
$number = $_POST['numbers'];
if(isset($_POST['check'])) {
$title .= "<BR>";
$title .= " ============================= ";
$title .= " <br> ===== GENERATED RESULT ===== " ."<BR>";
$title .= " ============================= ";
$title .= "<BR><BR>";
$values=$number;
while((int)$number!=0)
{
$remainder=$number%10;
$sum=$sum*10+$remainder;
$number=$number/10;
}
if($sum==$values)
{
$title .= "The " .$values." is a Palindrome Number.";
}
else
{
$title .= "The " .$values." is Not a Palindrome Number.";
}
}
if(isset($_POST['clear'])) {
$number = " ";
$title= " ";
}
?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
<br> <h1 align="center">Palindrome of Numbers</h2>
<form action="" method="post"><div>
<div class="row"><label> Enter a Number : </label> <input type="text" name="numbers"
value="<?php echo $values; ?>" autofocus required size=10/><br> </div><br>
<div class="button">
<input type="submit" name="check" value="Check Palindrome" id="submit"
title="Click here to findout if a number is palindrome or not."/>
<input type="submit" name="clear" value="Clear" id="submit"
title="Click here to clear text box and values on the screen"/> </div>
</form>
<br>
<?php
echo $title;
?>
</body>
</html>
No comments:
Post a Comment