<?php
$word = "Malayalam"; // declaring a varibale
echo "String: " . $word . "<br>";
$reverse = strrev($word); // reversing word
if ($word == $reverse) // comparing if original word is same as the reverse of the same word
echo 'Output: The string is a palindrome';
else
echo 'Output: This is not a palindrome';
?>
Find the string palindrome or not in PHP without using strrev() function.
<?php
$mystring = "madam"; // set the string
echo "String: " . $mystring;
$myArray = array(); // php array
$myArray = str_split($mystring); // split the array
$len = sizeof($myArray); // get the size of array
$newString = "";
for ($i = $len; $i >= 0; $i--) {
$newString.=$myArray[$i];
}
echo "<br>";
if ($mystring == $newString) {
echo "Output: " . $mystring . " is a palindrome";
} else {
echo "Output: " . $mystring . " is not a palindrome";
}
?>
Thanks for your informative article .its very useful
ReplyDeleteDot Net Training And Placement in Chennai
Software Testing Training Institute in Chennai
Java Classes in Chennai
Best PHP Course in Chennai