Código PHP:
$topic_number=0;
foreach ($topic_array as $topic_foreach)
{
if ($ads_dir_op_for_total = opendir($ads_dir))
{
$single_class_records_total=0;
while (false !== ($ads_dir_file_name_for_total = readdir($ads_dir_op_for_total)))
{
if (!is_dir($ads_dir_file_name_for_total))
{
if ((strlen($topic_number)) == strpos($ads_dir_file_name_for_total, "-") && (strstr($ads_dir_file_name_for_total, $topic_number . "-") == true))
{
$single_class_records_total++;
}