Menu
Coddy logo textTech

Challenge: Palindrome Checker

Part of the Logic & Flow section of Coddy's PHP journey — lesson 65 of 68.

challenge icon

Challenge

Easy

You will receive a single input: a string that may or may not be a palindrome.

A palindrome is a word or phrase that reads the same forwards and backwards when ignoring case. For example, "racecar", "level", and "Madam" are all palindromes.

Read the input string. Check if it is a palindrome by comparing it with its reversed version. Use string manipulation functions to reverse the string and compare it case-insensitively.

If the string is a palindrome, print: Palindrome

If the string is not a palindrome, print: Not a palindrome

Input format:

  • A single line containing a string (example: racecar or hello)

Expected output: Either Palindrome or Not a palindrome based on whether the input string reads the same forwards and backwards (case-insensitive)

Try it yourself

<?php
// Read input
$str = trim(fgets(STDIN));

// TODO: Write your code below to check if the string is a palindrome

// Output the result
echo $result;
?>

All lessons in Logic & Flow