Created
January 8, 2019 02:30
-
-
Save wisnubaldas/c531aef6f6f5a672368ec8ef6ccbeadf to your computer and use it in GitHub Desktop.
Palindrom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Palindrome | |
{ | |
public static function isPalindrome($string) { | |
//remove all spaces | |
$string = str_replace(' ', '', $string); | |
//remove special characters | |
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); | |
//change case to lower | |
$string = strtolower($string); | |
//reverse the string | |
$reverse = strrev($string); | |
if ($string == $reverse) { | |
return "<p>It is Palindrome</p>"; | |
} | |
else { | |
return "</p>Not Palindrome</p>"; | |
} | |
} | |
} | |
echo Palindrome::isPalindrome('Deleveled'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment