preg_replace() will do that nicely
/([i]stuff to match here[/i])(?=[^<>]*(?:<|$))/
That's totally off the top of my head, though. What it does is finds the pattern you're looking for, then scouts ahead to make sure there aren't any > characters before the next < (or the end of the string) turns up. The bit that's replaced will only be the stuff to match here bit.