Help us helping you.
I think the solution depends on where
are located, in database, in files on your disk or somewhere else.
As far as performing the actual replacement I myself would probably use substr_replace if possible but that is only since I am more comfortable with it.