Check for character which is not same in i + 1 and i - 1
for ( $ it = 0 ; $ it < strlen ( $ str ) ; $ it ++ ) { if ( $ str [ $ it ] != $ s [ $ i + 1 ] && $ str [ $ it ] != $ s [ $ i - 1 ] ) { $ s [ $ i ] = $ str [ $ it ] ; break ; } } }