ye strstr would be even better/faster.

just a short example, what to put in the foreach loop:

if(strstr($string,''.$file.'')){$count.=$count+1;}

now i don't have time, but maybe later if i will be free i will take a better look at it.