Home arrow PHP arrow Page 3 - Tracking Parsing Errors with the Tidy Library in PHP 5

Using the tidy_get_error_buffer() function - PHP

Creating well-formed (X)HTML documents can be a hard-to-accomplish task, particularly for PHP developers who need to focus mainly on the data and business layers of their web applications, and not on their visual presentation modules. However, this issue can be addressed with minor hassles with the assistance of the excellent Tidy extension.

  1. Tracking Parsing Errors with the Tidy Library in PHP 5
  2. Summarizing some Tidy library concepts
  3. Using the tidy_get_error_buffer() function
  4. Using the tidy_access_count(), tidy_error_count() and tidy_warning_count() functions
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
July 11, 2007

print this article



As I stated in the section that you just read, not surprisingly the Tidy library comes equipped with a neat group of functions whose primary capacity is to return to calling code all the errors raised when parsing a specified (X)HTML string.

Let me show you the first function that belongs to this specific group. It's called "tidy_get:error_buffer()," and it allows you to easily retrieve, from Tidy's error buffer, all the warnings raised when interpreting a concrete (X)HTML string. The corresponding code sample is as follows:

// example on using the ' tidy_get_error_buffer()' function
$html='<p>This paragraph will be parsed by tidy</p>';
echo tidy_get_error_buffer($tidy);

/* displays the following:
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: inserting missing 'title' element

As illustrated above, the "tidy_get_error_buffer()" function displays all the errors that occurred while parsing a concrete (X)HTML string. In this case, I coded some badly-formatted (X)HTML data, and then used the function to show the pertinent warnings thrown by "tidy_parse_string()." Not too complex, right?

However, as I said earlier, the Tidy library comes with a remarkable set of functions for retrieving all of the potential errors triggered when parsing some (X)HTML data. Therefore, in the following section I'm going to teach you how to use these additional error-handling functions. Click on the link that appears below and keep reading.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: