fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. $text = "А роза упала на лапу Азора";
  6. $result = 'палиндром';
  7.  
  8. $text = str_replace(' ', '', mb_strtolower($text));
  9.  
  10. $length = mb_strlen($text);
  11. $halfLength = floor($length / 2);
  12.  
  13. for($i=0;$i<=$halfLength;$i++) {
  14. $leftChar = mb_substr($text, $i, 1);
  15. $rightChar = mb_substr($text, $length -1 - $i, 1);
  16. if ($leftChar != $rightChar) {
  17. $result = 'не полиндром';
  18. break;
  19. }
  20. }
  21.  
  22. echo "Результат: {$result}\n";
Success #stdin #stdout 0.03s 25952KB
stdin
Standard input is empty
stdout
Результат: палиндром