主页
PHP
PHP preg_replace_callback_array() 函数
tryphp_func_regex_preg_replace_callback_array2
运行 ❯
×
更改方向
保存代码
更改主题
<?php function countLetters($matches) { return $matches[0] . '[' . strlen($matches[0]) . 'letter]'; } function countDigits($matches) { return $matches[0] . '[' . strlen($matches[0]) . 'digit]'; } $input = "365 days"; $patterns = [ '/[a-z]+/i' => 'countLetters', '/[0-9]+/' => 'countDigits' ]; $result = preg_replace_callback_array($patterns, $input); echo $result; ?>