Advertise on a video?

I am trying to make a website which the users will upload videos to.
But how can I set advertise on the videos?
Is there a way for doing it in PHP?
Because I saw alot of TEXT Advertises on Youtube Videos…
So I wondered how could I do that?

The advertisements are actually implemented by whatever is displaying the video, not PHP. I’m assuming its done in flash.