diff --git a/solution/0100-0199/0125.Valid Palindrome/README.md b/solution/0100-0199/0125.Valid Palindrome/README.md index 6ad4d22b6a195..f301362baa837 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README.md +++ b/solution/0100-0199/0125.Valid Palindrome/README.md @@ -308,6 +308,30 @@ func verify(ch byte) bool { } ``` +### **PHP** + +```php +class Solution { + /** + * @param String $s + * @return Boolean + */ + function isPalindrome($s) { + $regex = "/[a-z0-9]/"; + $s = strtolower($s); + preg_match_all($regex, $s, $matches); + if ($matches[0] == Null) return true; + $len = floor(count($matches[0]) / 2); + for ($i = 0; $i < $len; $i++) { + if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) { + return false; + } + } + return true; + } +} +``` + ### **...** ``` diff --git a/solution/0100-0199/0125.Valid Palindrome/README_EN.md b/solution/0100-0199/0125.Valid Palindrome/README_EN.md index 8c2957cdbf523..8f6a681034ac0 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README_EN.md +++ b/solution/0100-0199/0125.Valid Palindrome/README_EN.md @@ -296,6 +296,30 @@ func verify(ch byte) bool { } ``` +### **PHP** + +```php +class Solution { + /** + * @param String $s + * @return Boolean + */ + function isPalindrome($s) { + $regex = "/[a-z0-9]/"; + $s = strtolower($s); + preg_match_all($regex, $s, $matches); + if ($matches[0] == Null) return true; + $len = floor(count($matches[0]) / 2); + for ($i = 0; $i < $len; $i++) { + if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) { + return false; + } + } + return true; + } +} +``` + ### **...** ``` diff --git a/solution/0100-0199/0125.Valid Palindrome/Solution.php b/solution/0100-0199/0125.Valid Palindrome/Solution.php new file mode 100644 index 0000000000000..454272a80e6a9 --- /dev/null +++ b/solution/0100-0199/0125.Valid Palindrome/Solution.php @@ -0,0 +1,19 @@ +class Solution { + /** + * @param String $s + * @return Boolean + */ + function isPalindrome($s) { + $regex = "/[a-z0-9]/"; + $s = strtolower($s); + preg_match_all($regex, $s, $matches); + if ($matches[0] == Null) return true; + $len = floor(count($matches[0]) / 2); + for ($i = 0; $i < $len; $i++) { + if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) { + return false; + } + } + return true; + } +} \ No newline at end of file