Find the count of palindromic sub | PHP program to find the count of palindromic sub - string of a string in it 's ascending form ; function to return count of palindromic sub - string ; calculate frequency ; calculate count of palindromic sub - string ; return result ; Driver Code
< ? php $ MAX_CHAR = 26 ; function countPalindrome ( $ str ) { global $ MAX_CHAR ; $ n = strlen ( $ str ) ; $ sum = 0 ; $ hashTable = array_fill ( 0 , $ MAX_CHAR , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ hashTable [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] ++ ; for ( $ i = 0 ; $ i < 26 ; $ i ++ ) { if ( $ hashTable [ $ i ] ) $ sum += ( int ) ( $ hashTable [ $ i ] * ( $ hashTable [ $ i ] + 1 ) / 2 ) ; } return $ sum ; } $ str = " ananananddd " ; echo countPalindrome ( $ str ) ; ? >