Configuration
Like the cURL extension, the tidy extension operates largely on the concept of configuration; hence, $config parameters are present in all calls in the above example. Unlike most other extensions, this parameter can actually be one of two things: an associative array of setting-value pairs or the path to an external configuration file. The configuration file format is somewhat similar to individual style settings in a CSS stylesheet. An example is shown below. It’s unlikely that a non-developer will need to access the configuration settings and not the PHP source code using tidy as well. As such, separation into an external configuration file is really only useful for the sake of not cluttering source code with settings. Additionally, because the configuration file is read from disk, it may pose performance concerns when in high use. // single-line comment /* multi-line comment */ indent: false /* setting: value */ wrap: 78 When using the object-oriented API, an alternative to using configuration files is subclassing the tidy class and overriding its parseString and parseFile methods to automatically include specific configuration setting values. This method allows for easy reuse of tidy configurations. <?php class mytidy extends tidy { private $_default = array( 'indent' => false, 'wrap' => 78 ); public function parseFile($filename, $config, $encoding, $use_include_path=false) { return parent::parseFile( $filename, array_merge($this->_default, $config), $encoding, $use_include_path ); ) public function parseString($filename, $config, $encoding $use_include_path=false) { return parent::parseString( $filename, array_merge($this->_default, $config), $encoding, $use_include_path ); } } ?>
© Tidy Extension — Web Scraping >>> Back to TABLE OF CONTENTS <<< | |
Views: 358 | |
Total comments: 0 | |