运行 ❯
获取您
自己的 PHP
服务器
×
更改方向
更改主题,深色/浅色
前往 Spaces
<!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> </html>
一年[4字]有[1字]365[3位]天[1字]。