Exécuter
❯
Exécuter le code
Ctrl+Alt+R
Changer d'orientation
Ctrl+Alt+O
Changer de thème
Ctrl+Alt+D
<!DOCTYPE html> <html> <body> <?php function countLetters($matches) { return $matches[0] . '[' . strlen($matches[0]) . 'lettre]'; } function countDigits($matches) { return $matches[0] . '[' . strlen($matches[0]) . 'chiffre]'; } $input = "Il y a 365 jours dans une année."; $patterns = [ '/\b[a-z]+\b/i' => 'compterLettres', '/\b[0-9]+\b/' => 'compterChiffres' ]; $result = preg_replace_callback_array($patterns, $input); echo $result; ?> </body> </html>
Il y a 365 jours dans une année.