<?php

error_reporting(-1);
mb_check_encoding('utf-8');
header("Content-Type: text/plain; charset=utf-8");

$text = 'А муза рада музе без ума да разума';

$textUpper = mb_strtoupper($text);
$textWithoutSpace = str_replace(" ", "", $textUpper);
$lengthStr = mb_strlen($textWithoutSpace);
$lengthStr--;
$saveLenght = $lengthStr;
$check = 0;

for ($i = 0; $i <= $saveLenght; $i ++) {
    $firstSymbol = mb_substr($textWithoutSpace, $i, 1);
    $lastSymbol = mb_substr($textWithoutSpace, $lengthStr, 1);
    $lengthStr --;
    if ($firstSymbol == $lastSymbol) {
        $check ++;
    }
}

$saveLenght ++;

echo "Исходный текст: {$text}. \n";

if ($check == $saveLenght) {
    echo 'Палиндром';
} else {
    echo 'Не Палиндром';
}