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

Summarizing some Tidy library concepts - 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Before I move on, I'd first like to remind you of the most important topics treated in the preceding article of the series. This review should help you see more easily how the Tidy functions learned in that tutorial can be linked with the ones that I plan to cover in a few moments.

Having said that, below I listed some basic examples of how to use the hopefully familiar "tidy_get_html()," "tidy_get_head()" and "tidy_get_body()" functions, which are tasked with extracting the different sections of a specified (X)HTML string. Here are the corresponding code samples; have a look at them please:

// example on using the 'tidy_get_html()' function

$html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html
xmlns="http://www.w3.org/1999/xhtml"><head><title>Testing
Tidy</title></head><body><p>Testing Tidy</p></body></html>';
$tidy=tidy_parse_string($html);
$htmlNode=tidy_get_html($tidy);
echo $htmlNode->value;

/* displays the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Testing Tidy</title>
</head>
<body><p>Testing Tidy</p>
</body>
</html>
*/

// example on using the 'tidy_get_head()' function

$html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html
xmlns="http://www.w3.org/1999/xhtml"><head><title>Testing
Tidy</title></head><body><p>Testing Tidy</p></body></html>';
$tidy=tidy_parse_string($html);
$headNode=tidy_get_html($tidy);
echo $headNode->value;

/* displays the following:
<head>
  <title>Testing Tidy</title>
</head>
*/

// example on using the 'tidy_get_body()' function

$html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html
xmlns="http://www.w3.org/1999/xhtml"><head><title>Testing
Tidy</title></head><body><p>Testing Tidy</p></body></html>';
$tidy=tidy_parse_string($html);
$bodyNode=tidy_get_body($tidy);
echo $bodyNode->value;

/* displays the following:
<body>
  <p>Testing Tidy</p>
</body>
*/

Hopefully, after studying the respective signatures for the three previous examples, you'll recall how easy it is to extract the distinct sections of a specified (X)HTML string using the functions provided by the Tidy library. Nonetheless, I believe that these functions in particular don't bear any additional discussion, since they were already covered in detail in the previous tutorial of the series.

Therefore, it's a good time to move forward and start looking into the group of Tidy functions aimed specifically at handling all the errors that occur when parsing a concrete (X)HTML string.

Want to see how these brand new functions will be properly implemented? Click on the link below and keep reading.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: