The behaviour of these functions is affected by settings in php.ini.
Here's a short explanation of the configuration directives.
tidy.default_config
Default path for tidy config file.
tidy.clean_output
Turns on/off the output repairing by Tidy.
Do not turn on tidy.clean_output if you are generating non-html content such as dynamic images.