Challenge: Palindrome Checker
Part of the Logic & Flow section of Coddy's PHP journey — lesson 65 of 68.
Challenge
EasyYou 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:
racecarorhello)
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
1Advanced Functions
Anonymous FunctionsClosures and 'use'Arrow FunctionsCallback FunctionsUsing 'call_user_func'Variable FunctionsPassing by ReferenceRecursive FunctionsRecap: Function Medley4Multi-dimensional Arrays
Creating a 2D ArrayAccessing 2D Array ElementsModifying 2D Array ElementsIterating with Nested Loops2D Associative ArraysRecap: Simple Grid Exercise7Working with Dates and Times
The 'date()' FunctionUnix Timestamps with 'time()'Intro to the DateTime ObjectFormatting DateTime ObjectsModifying DateTime ObjectsRecap: Date Calculations10Final Challenges
Challenge: Palindrome CheckerChallenge: Character FrequencyChallenge: Shopping Cart TotalChallenge: Unique Item Filter2Advanced Array Manipulations
Adding with 'array_push'Removing with 'array_pop'Adding with 'array_unshift'Removing with 'array_shift'Merging Indexed ArraysMerging Associative ArraysExtracting with 'array_slice'Values with 'in_array'Keys with 'array_search'Recap: Playlist Exercise3Sorting Arrays
Sort Indexed Arrays AscendingSort Indexed Arrays DescendingSort Assoc Arrays by ValueSort Assoc Arrays by KeyNatural Order SortingCustom Sorting with 'usort'Recap: Leaderboard Sorting