我知道我可以找到 preg_match_all 的出现
即
<?php
$text = 'here is JUICE. it is good JUICE...';
$counted = preg_match_all('/JUICE/',$text,$empt);
echo $counted;
?>
但我如何计算 preg_replace 的出现次数?
最佳答案
根据 the manual ,还有一个可选的第 5 个参数 $count
,它将被设置为执行替换的次数:
preg_replace($pattern, $replacement, $subject, -1, $count)
第四个参数是替换次数的$limit
。 -1
表示没有限制
关于php - 计算 preg_replace 正则表达式中的出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24452641/