fork download
  1. <?php
  2.  
  3. $total = numberOfReplacements('Привeт', 'Привет', 'Cyrillic');
  4. echo "Замена киррилицы латиницей: $total симв.\n";
  5.  
  6. $total = numberOfReplacements('hаbr', 'habr', 'Latin');
  7. echo "Замена латиницы киррилицей: $total симв.";
  8.  
  9.  
  10. function numberOfReplacements(string $input, string $original, string $pattern): int
  11. {
  12. $pattern = preg_quote($pattern, '~');
  13. $match = preg_match_all("~\p{{$pattern}}~u", $input);
  14. $total = mb_strlen($original);
  15.  
  16. return $total - $match;
  17. }
Success #stdin #stdout 0.03s 24552KB
stdin
Standard input is empty
stdout
Замена киррилицы латиницей: 1 симв.
Замена латиницы киррилицей: 1 симв.