logo CodeStepByStep logo


Language/Type: PHP string parameters return Boolean

Write a function named is_palindrome that accepts a string parameter and returns true if that string is a palindrome, or false if it is not a palindrome.

For this problem, a palindrome is defined as a string that contains exactly the same sequence of characters forwards as backwards, case-insensitively. For example, "madam" or "racecar" are palindromes, so the call of is_palindrome("racecar") would return true. Spaces, punctuation, and any other characters should be treated the same as letters; so a multi-word string such as "dog god" could be a palindrome, as could a gibberish string such as "123 $ 321". The empty string and all one-character strings are palindromes by our definition. Your code should ignore case, so a string like "Madam" or "RACEcar" would also count as palindromes.

Type your PHP solution code here:

This is a function exercise. Write a PHP function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.