Created
October 20, 2015 14:47
-
-
Save d30jeff/c31f69ce406b68bf0fa3 to your computer and use it in GitHub Desktop.
Check Palindrome
This file contains hidden or 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 | |
| $input = "was it a car or a cat I saw?"; | |
| $input = preg_replace("/[^a-zA-Z0-9]/", "", $input); | |
| $string = strtolower(implode("", str_split(str_replace(' ', '', $input)))); | |
| $evenOrOdd = function($string) { | |
| return (strlen($string) % 2 == 0) ? "even" : "odd"; | |
| }; | |
| echo ($string == strrev($string)) ? "Is an {$evenOrOdd($string)} palindrome." : "Not a palindrome."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment