Standard Palindrome in PHP

A Standard Palindrome is a word or phrase that is the same forward as it is backwards without punctuation and spaces. So here is a small script that strips everything but letters and numbers in a string and finds if it’s a palindrome.

There isn’t much need to explain how it works, just replace the $originalpalindrome with the word or phrase you want to test.
<?php
$originalpalindrome = "Madam I'm Adam";
$palindrome = strtolower(preg_replace("([^A-Za-z0-9])", "", $originalpalindrome ));
$palindrome2 = strtolower(strrev($palindrome));
echo "Original Statement: $originalpalindrome <br /><br />";
if ($palindrome == $palindrome2){
echo "$palindrome is a Standard Palindrome of $palindrome2";
}else{
echo "$palindrome is <strong>not</stong> a Standard Palindrome of $palindrome2";
};
?>

  • Meh

    You should work on clean code. If you have palindrome2, the other variable should be palindrome1.

    Also, use white space. Indenting is good too for legibility.