I read through some of the other messages AFTER modifying/fixing the original script, I would have added the <?php ?> <php> </php> stuff but I can't be arsed. On a deadline for other stuff.
That said, attached is an updated version that uses output buffering (in case you want to echo text) and also fixes the str_replace that didn't do squat
Mail me at stephen AT natnet DOT com if you want to say thanks or have questions, today was my first day on the board and I probably won't be back (fixed for a client who wanted to use phpAdsNew).