I'm not sure I understand what you are talking about exactly. The generation of the content can be done in many different ways, and the ads themselves can be from any place. It really depends. Are you looking for some kind of ad manager or some other ad-related php script?
If you are just looking around php then check out the cURL [uk2.php.net] functions. As these enable you to use php a bit like a browser and get content from other sites, check that links you are directing people to are not returning 404's or redirecting people off to other sites or lots of other interesting things. There are a lot of things that you can do with cURL, and adds is one of them.