My goal is to reliably count the number of matches in a preg_match_all operation.
The following code works fine in a separate PHP page. However, it does NOT work when I include it in other php code. Same code: different result.
preg_match_all('/[0-9]{1,}[-]{1}[0-9]{1,}/',$txt,$matches);
$c=count($matches[0]);
preg_match_all('/[A-Za-z]{1,}[-]{1}[A-Za-z]{1,}/',$txt,$matches);
$d=count($matches[0]);
echo "c count=".$c;
echo "d count="$d;
Why does this code NOT work when I include it in other PHP code, even though this code works in a php page by itself?
How can I reliably count the number of matches in a preg_match_all operation. I know I use "matches" and I know there are nested arrays. However the statement count($matches[0]) does not always work.