Skip to content

Instantly share code, notes, and snippets.

@d30jeff
Created October 20, 2015 14:47
Show Gist options
  • Select an option

  • Save d30jeff/c31f69ce406b68bf0fa3 to your computer and use it in GitHub Desktop.

Select an option

Save d30jeff/c31f69ce406b68bf0fa3 to your computer and use it in GitHub Desktop.
Check Palindrome
<?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