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
<?php

function isPalindrome(string $text): bool {
    $clean = strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $text));
    return $clean === strrev($clean);
}
solution.php