When I was younger, my sister got worms - from picking her nose and eating it - mmmmm, that's what we were told anyway, but the whole family had to be medicated.
At the time, it was a blood-red medicine which was ABSOLUTELY foul tasting and we had to take more than her even though she was the one who had it! Very unfair!
Apparently young children can get them from not washing hands after using the toilet and from pet excreta (especially dog). I know there was a reason why I am forever going on at my ds about washing hands after the loo.
It looks like it is very easy to get worms from children playing closely together as HMB says, the eggs enter the mouth. Then they grow into adult worms in the gut (apologies if you are eating!).