function cleanText(string $text) {
$cleaned = [];
foreach (str_split($text) as $i=>$letter) {
if ($letter === "&" || $text[$i-1] === "&") {
continue;
}
$cleaned[] = $letter;
}
return implode("", $cleaned);
}
upd: второй вопрос
function justify(string $someWord, string $otherWord) {
$spaces = "";
if (strlen($someWord) !== strlen($otherWord)) {
$diff = abs(mb_strlen($someWord)-mb_strlen($otherWord));
$offset = ceil($diff/2);
$spaces = str_repeat(" ", $offset);
}
if (mb_strlen($someWord) >= mb_strlen($otherWord)) {
return $someWord . PHP_EOL . $spaces . $otherWord;
} else {
return $spaces . $someWord . PHP_EOL . $otherWord;
}
}