How to achieve the input string This is an Apple on eBay output Siht si na Elppa no yAbe

. 1 ? < PHP
 2  $ STR = "This IS AN ON eBay the Apple"; // definition string 
. 3  $ len = strlen ( $ STR ); // string length 
. 4  $ SUP = []; // empty array, with capital letters recorded position
 5  // string loop 
. 6  for ( $ I = 0; $ I < $ len ; $ I ++ ) {
 . 7      // if the current letter is capitalized, then converted to lower case, the front and rear unequal 
. 8      IF ( $ STR [ $ I ]! = strtolower ( $ STR[ $ I ])) {
 . 9          $ SUP [] = $ I ; // record uppercase positions 
10      }
 . 11  }
 12 is  // print_r ($ SUP);
 13 is  // string into an array of 
14  $ ARR = the explode ( " "," This iS AN oN eBay the Apple " );
 15  // result is the empty string, store conversion 
16  $ new_str =" " ;
 . 17  // loop through the array of processing elements 
18 is  the foreach ( $ ARR  AS  $ K = > $ V ) {
 . 19      // inverted and converted to lower case, a space stitching 
20     new_str $ =. strtolower ( strrev ( $ V )) "." ;
 21 is  }
 22 is  // remove trailing spaces 
23 is  $ new_str = TRIM ( $ new_str );
 24  // circulating capital position array 
25  the foreach ( $ SUP  AS  $ V ) {
 26 is      // location where the new string conversion uppercase 
27      $ new_str [ $ V ] = the strtoupper ( $ new_str [ $ V ]);
 28  }
 29  
30  echo $ new_str ;
31  // Siht na si Elppa no yAbe 
32 ?>

 

Guess you like

Origin www.cnblogs.com/songbao/p/11272803.html