Recursive function to check if a string is palindrome | A recursive function that check a str [ s . . e ] is palindrome or not . ; If there is only one character ; If first and last characters do not match ; If there are more than two characters , check if middle substring is also palindrome or not . ; An empty string is considered as palindrome ; Driver Code
< ? php function isPalRec ( $ str , $ s , $ e ) { if ( $ s == $ e ) return true ; if ( $ str [ $ s ] != $ str [ $ e ] ) return false ; if ( $ s < $ e + 1 ) return isPalRec ( $ str , $ s + 1 , $ e - 1 ) ; return true ; } function isPalindrome ( $ str ) { $ n = strlen ( $ str ) ; if ( $ n == 0 ) return true ; return isPalRec ( $ str , 0 , $ n - 1 ) ; } { $ str = " geeg " ; if ( isPalindrome ( $ str ) ) echo ( " Yes " ) ; else echo ( " No " ) ; return 0 ; } ? >