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