Thursday, April 26, 2018

Check wether a given string is Palindrome or not

<?php
class Palindrome
{
    public static function isPalindrome($word)
    {
       
    $string = str_replace(' ', '', $word);


    $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string);

    $string = strtolower($string);

    $reverse = strrev($string);

    if ($string == $reverse) {
       return true;
    }
    else {
        return false;
    }
       
    }
}

echo Palindrome::isPalindrome('nitin');
?>

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...