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 = "365 jours"; $patterns = [ '/[a-z]+/i' => 'compterLettres', '/[0-9]+/' => 'compterChiffres' ]; $result = preg_replace_callback_array($patterns, $input); echo $result; ?> </body> </html>
365[3chiffre] jours[4[1chiffre]lettre]