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