Created
August 25, 2011 11:32
-
-
Save cypres/1170470 to your computer and use it in GitHub Desktop.
Palindrome tester (UTF-8 compatible)
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
function palindromeTest($i) { | |
preg_match_all('/([\\x41-\\x5A\\x61-\x7A])|([\\xC0-\\xDF].)|([\\xE0-\\xEF]..)|([\\xF0-\\xFF]...)]/',$i,$m); | |
$a = mb_strtolower(implode('',$m[0]),'UTF-8'); | |
$b = mb_strtolower(implode('',array_reverse($m[0])),'UTF-8'); | |
return ($a == $b); | |
} | |
var_dump(palindromeTest('Syy hyökätä: köyhyys!')); // true | |
var_dump(palindromeTest('Syy hyäkötä: köyhyys!')); // false | |
var_dump(palindromeTest('Selmas lakserøde garagedøre skal samles')); // true | |
var_dump(palindromeTest('a€b€a')); // true (U+20AC test) | |
var_dump(palindromeTest('a𝀸b𝀸a')); // true (U+1D038 test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the git clone URLs or the download button, the gist system don't support displaying UTF-8 chars apparently.