Well, the next step for me would be to take portions of the offending code and create a test php page to run in the command line with appropriate debugging to see where the error is being introduced.
Since this is really off topic to the sme formums, I'd be happy to continue this discussion by email: I'm at larry at tm-wd dot com.
Larry