why don't you just use preg_match to count the duplicates?

i know that this is slower but as the above one doesn't work, you could try this.