Skip to content

Instantly share code, notes, and snippets.

@akatgelar
Last active May 24, 2019 17:24
Show Gist options
  • Save akatgelar/e3864dabbf09e0e996181c6a58548b26 to your computer and use it in GitHub Desktop.
Save akatgelar/e3864dabbf09e0e996181c6a58548b26 to your computer and use it in GitHub Desktop.
<?php
class Palindrome
{
public static function isPalindrome($word)
{
$word = str_replace(' ', '', $word);
$word = preg_replace('/[^A-Za-z0-9\-]/', '', $word);
$word = strtolower($word);
$word_ = strrev($word);
if ($word_ == $word) {
return true;
}
else {
return false;
}
}
}
echo Palindrome::isPalindrome('Deleveled');
@joshbutkovic
Copy link

joshbutkovic commented May 24, 2019

I'm baffled, for some reason this doesn't pass and I cannot get anything to pass. I feel like the tests are broken... WDYT?

my code was:

function isPalindrome(string $word): bool
{
    if (preg_match("/^[a-zA-Z ]*$/i", $word)) {
        $wordArray = str_split(strtolower($word));
        if ($wordArray === array_reverse($wordArray)) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

@joshbutkovic
Copy link

Ok scratch that your answer does work, I guess it wants you actually call the function, nm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment