I know that with I can find of occurrences with preg_match_all
i.e.
<?php
$text = 'here is JUICE. it is good JUICE...';
$counted = preg_match_all('/JUICE/',$text,$empt);
echo $counted;
?>
but how can I count occurrences with preg_replace?
I know that with I can find of occurrences with preg_match_all
i.e.
<?php
$text = 'here is JUICE. it is good JUICE...';
$counted = preg_match_all('/JUICE/',$text,$empt);
echo $counted;
?>
but how can I count occurrences with preg_replace?
As per the manual, there is an optional 5th parameter $count
, which will be set to the number of replacements performed:
preg_replace($pattern, $replacement, $subject, -1, $count)
The 4th parameter is the $limit
on the number of replacements. -1
means no limit.