Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:10:15+00:00 2026-06-09T00:10:15+00:00

The PHP tidy extension has a function ob_tidyhandler Docs that works with PHP output

  • 0

The PHP tidy extension has a function ob_tidyhandlerDocs that works with PHP output bufferingDocs as a callback, e.g.:

ob_start('ob_tidyhandler');

I know that Tidy has a lot of configuration settingsDocs, however I am hitting a road block to setup default configuration options for that output buffer callback.

Most of Tidy’s PHP function refer to a tidy document or object, however with the output buffering that one is not accessible.

There is a configuration setting tidy.default_config, however that is not change-able at runtime, so it is not very dynamic.

Does anybody know if configuring the callback dynamically is possible at all? I remember I wrote a callback my own, collected all output and repaired it with a call to tidy_repair_stringDocs which accepts configuration as an array. But I thought it would be nice to not need to do that and just pass the configuration along for the output buffer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:10:16+00:00Added an answer on June 9, 2026 at 12:10 am

    I’ve had a quick look at the code for the tidy extension, and there is a way to change the configuration for the output buffer handler.

    That said, it is not a nice way. It is exploiting a feature of the code which obviously may change in future versions.

    The function that handles the buffer processing is php_tidy_output_handler and on line 1191 it calls the macro TIDY_SET_DEFAULT_CONFIG.

    If tidy.default_config is not set, then the macro does nothing. If it is set then the configuration file is read from disk and the options are parsed.

    Since the configuration file is loaded during the parsing of the output buffer, it is possible to modify the configuration file from your PHP script before parsing begins.

    This means you have to make tidy.default_config = /file/writable/by/php and dynamically update this file to contain the options you require. (I told you it was not a nice way).


    I can immediately see a problem with this. There is a potential race condition.

    If two scripts require different options, and both are executed at the same time, there is the potential for one of the scripts to receive the wrong configuration.

    The file is obviously not designed to be changed ad-hocly – and as you can probably follow from the extension code, there is no other available path to inject configuration options, since the options are specific to the document.

    • A new TidyDoc is created.
    • Couple of config flags set + default_config loaded.
    • Buffer is parsed.

    Sorry, it feels like in the end I am just delivering bad news.

    Your best solution may be to go with a custom ob_start callback where you have full control over the document options.

    Edit:

    Had a bit of a brainstorm and tried a few things to get around this. Everything has been met with failure.

    I tried registering a custom stream wrapper to return per-script values, and set tidy.default_config = tidy://config. It turns out that stream wrappers are not resolved by the config loader and this does not work.

    One thing I have not been able to test correctly is the per-directory configuration .user.ini or the [PATH=] ini section. These are both only available with the CGI/FastCGI SAPI (not FPM). I suspect this probably doesn’t help you either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using php extension tidy-html to clean up php output. I know that tidy
I have HTML tidy extension on my home computer using PHP 5.2.11 (Windows -
When using the PHP Tidy Library (More Specifically, The tidy_repair_string function) I keep getting
PHP has PHP-FPM, a pool of PHP processes that run, are managed, go away
PHP: I have made up a function that returns an array. I would like
I have a PHP Script that loads an rss feed, parses it through Tidy
I know there is tidy php class by default already, what about if I
PHP has some pretty inconsistent parameters for functions (e.g. sometimes first haystack , then
I wrote an extension in C++ that uses libtidy, and it runs perfectly under
I want to extract particular part of HTML using tidy in php. the html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.