Skip to content

Instantly share code, notes, and snippets.

@wisnubaldas
Created January 8, 2019 02:30
Show Gist options
  • Save wisnubaldas/c531aef6f6f5a672368ec8ef6ccbeadf to your computer and use it in GitHub Desktop.
Save wisnubaldas/c531aef6f6f5a672368ec8ef6ccbeadf to your computer and use it in GitHub Desktop.
Palindrom
<?php
class Palindrome
{
public static function isPalindrome($string) {
//remove all spaces
$string = str_replace(' ', '', $string);
//remove special characters
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string);
//change case to lower
$string = strtolower($string);
//reverse the string
$reverse = strrev($string);
if ($string == $reverse) {
return "<p>It is Palindrome</p>";
}
else {
return "</p>Not Palindrome</p>";
}
}
}
echo Palindrome::isPalindrome('Deleveled');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment