fork download
  1. <?php
  2.  
  3.  
  4. $text = "Аргентина манит негра";
  5. $lowText = mb_strtolower($text);
  6. $a = 0;
  7. $b = -1;
  8. $noSpace = str_replace(" ", "", $lowText);
  9. $countText = mb_strlen($noSpace);
  10. $halfLenght = floor($countText / 2);
  11. for ($i = 0; $i <= $halfLength; $i++) {
  12.  
  13. $letter1 = mb_substr($noSpace, $a, 1);
  14. $letter2 = mb_substr($noSpace, $b, 1);
  15.  
  16. if ($letter1 != $letter2) {
  17. $palindrome = false;
  18. $i = $halfLenght++;
  19. }
  20. else {
  21. $palindrome = true;
  22. $a++;
  23. $b--;
  24. }
  25. }
  26. if ($palindrome == true) {
  27. echo "Это Полиндром";
  28. }
  29. else {
  30. echo "Это не полиндром";
  31. }
  32.  
  33. var_dump($halfLenght);
  34. var_dump($letter1);
  35. var_dump($palindrome);
  36.  
Success #stdin #stdout #stderr 0.02s 52432KB
stdin
Standard input is empty
stdout
Это Полиндромfloat(9)
string(2) "а"
bool(true)
stderr
PHP Notice:  Undefined variable: halfLength in /home/1kSN4e/prog.php on line 13
PHP Notice:  Undefined variable: halfLength in /home/1kSN4e/prog.php on line 13