if ((strlen($str) == 1) || (strlen($str) == 0)) { echo " THIS IS PALINDROME"; }
If strlen($str) <= 1 , then this is obviously a palindrome.
else { if (substr($str,0,1) == substr($str,(strlen($str) - 1),1)) { return Palindrome(substr($str,1,strlen($str) -2)); }
If strlen($str) > 1 and if the first and last characters of the string are similar, call the same Palindrome function on the internal string (this is a string without its first and last characters).
else { echo " THIS IS NOT A PALINDROME"; } }
If the first and last characters are not equal, this is not a palindrome.
The principle is to check only external characters and call the same function again and again on small parts of the string until it checks each pair of characters that should be equal if we are dealing with a palindrome.
This is called recursion .
This image illustrates what happens better than my poor English can:

image source
source share