Source Code :=>
$x="madam"; //Input String
checkPalindrom($x); //function Calling
function checkPalindrom($x) //function Definition
{
$len=strlen($x); //get String Length
$p=substr($x,0,1); //get First Char
$q=substr($x,$len-1,$len); //get Last char
if($p===$q)
{
if($x!=' ' && strlen($x)!=0)
{
$x=substr($x,1,$len-2); //get String with Remove first & last char of New String.
checkPalindrom($x);
}
else
echo "True,It's Palindrome.";
}
else
{
die("No,It's not Palindrome.");
}
}
?>
Output :=>
True,It's Palindrome.
<?php
$x="madam"; //Input String
checkPalindrom($x); //function Calling
function checkPalindrom($x) //function Definition
{
$len=strlen($x); //get String Length
$p=substr($x,0,1); //get First Char
$q=substr($x,$len-1,$len); //get Last char
if($p===$q)
{
if($x!=' ' && strlen($x)!=0)
{
$x=substr($x,1,$len-2); //get String with Remove first & last char of New String.
checkPalindrom($x);
}
else
echo "True,It's Palindrome.";
}
else
{
die("No,It's not Palindrome.");
}
}
?>
Output :=>
True,It's Palindrome.
No comments:
Post a Comment