05. Palindrome Phrase Inspector 05. Palindrome Phrase Inspector
Easy
+15 Points
Deskripsi Tantangan Problem Description
Buat fungsi `isPalindrome($text)` yang mengembalikan `true` jika kata/kalimat adalah palindrom (dibaca sama dari depan & belakang, abaikan spasi & kapitalisasi), dan `false` jika bukan.
Create a function `isPalindrome($text)` that returns `true` if a phrase is a palindrome (ignoring spaces, punctuation & case), and `false` otherwise.
Example Test Cases
Input: ["Kasur ini rusak"]
Expected Output: true
Input: ["A man a plan a canal Panama"]
Expected Output: true
- Bersihkan spasi dan tanda baca dengan preg_replace().
- Ubah ke lowercase dengan strtolower().
- Bandingkan string dengan pembalikannya strrev().
- Clean punctuation & spaces with `preg_replace()`.
- Lowercase the string.
- Compare string with its reverse `strrev()`.
<?php
function isPalindrome(string $text): bool {
$clean = strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $text));
return $clean === strrev($clean);
}
solution.php
Test Case #
Input:
Expected:
Actual Output:
Error: