Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<?php
function countLetters($matches) {
  return $matches[0] . '[' . strlen($matches[0]) . 'letter]';
}
function countDigits($matches) {
  return $matches[0] . '[' . strlen($matches[0]) . 'digit]';
}
$input = "There are 365 days in a year.";
$patterns = [
  '/\b[a-z]+\b/i' => 'countLetters',
  '/\b[0-9]+\b/' => 'countDigits'
];
$result = preg_replace_callback_array($patterns, $input);
echo $result;
?>
</body>
<!-- Mirrored from www.w3schools.com/php/phptryit.asp?filename=tryphp_func_regex_preg_replace_callback_array by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 17:22:58 GMT -->
</html>
There[5letter] are[3letter] 365[3digit] days[4letter] in[2letter] a[1letter] year[4letter].