text: Replace every character of string by character whose ASCII value is K times more than it | Function to move string character ; changed string ; iterate for every characters ; ASCII value ; store the duplicate ; if k - th ahead character exceed ' z ' ; print the new string ; Driver code ; function call
code: < ? php function encode ( $ s , $ k ) { $ newS = " " ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; ++ $ i ) { $ val = ord ( $ s [ $ i ] ) ; $ dup = $ k ; if ( $ val + $ k > 122 ) { $ k -= ( 122 - $ val ) ; $ k = $ k % 26 ; $ newS = $ newS . chr ( 96 + $ k ) ; } else $ newS = $ newS . chr ( $ val + $ k ) ; $ k = $ dup ; } echo $ newS ; } $ str = " abc " ; $ k = 28 ; encode ( $ str , $ k ) ; ? >