fork download
  1. <?php
  2.  
  3.  
  4. $text = "А роза упала на лапу Азора";
  5. $result = "палиндром";
  6.  
  7. $text = mb_strtolower($text);
  8. $length = mb_strlen($text);
  9. $textWithoutSpaces = str_replace(" ", "", $text);
  10.  
  11. $length = mb_strlen($textWithoutSpaces);
  12. $halfLength = floor($length/2);
  13.  
  14. for ($i = 0; $i < $halfLength; ++$i) {
  15. $charOne = mb_substr($textWithoutSpaces, $i, 1);
  16. $charTwo = mb_substr($textWithoutSpaces, -($i + 1), 1);
  17.  
  18. if ($charOne != $charTwo) {
  19. $result = "это не палиндром";
  20. break;
  21. }
  22. }
  23.  
  24. echo $result;
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
палиндром