<?php

$total = numberOfReplacements('Привeт', 'Привет', 'Cyrillic');
echo "Замена киррилицы латиницей: $total симв.\n";

$total = numberOfReplacements('hаbr', 'habr', 'Latin');
echo "Замена латиницы киррилицей: $total симв.";


function numberOfReplacements(string $input, string $original, string $pattern): int
{
    $pattern = preg_quote($pattern, '~');
    $match = preg_match_all("~\p{{$pattern}}~u", $input);
    $total = mb_strlen($original);

    return $total - $match;
}