Showing posts with label PHP Tidy Object. Show all posts
Showing posts with label PHP Tidy Object. Show all posts

Sunday, March 4, 2012

Remove HTML comments PHP

Cleaning or Removing HTML comments is one of the main part of Optimizing web pages. Here is the solution to Remove HTML Comments with PHP.

To Remove HTML Comments in PHP, We need to use the following Technique.

Remove HTML Comments with PHP
// Start OutputBuffer
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Remove HTML Comments</title>

<!-- // HTML Comments for code identification -->

<!-- Mutiple Closing Tags-->
<h1>Remove HTML Comments Example</h1>
<!-- Unclose End Tag-->
<p>This is an example to remove HTML Comments <p>

// Store HTML Output Buffer as variable with ob_get_clean();
$html = ob_get_clean();

// Specify configuration
$config = array(
           'indent'         => false,
     'hide-comments' => true,
           'output-xhtml'   => true,
           'wrap'           => false

// Tidy
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');

// Output
echo $tidy;

Friday, March 2, 2012

PHP Tidy - Clean HTML Tags, HTML code, HTML Source, Comments

Website Webpage Optimization part, HTML pages contain many unnecessary development usage section such as Comments, Indents, Empty Lines, Accidental Enclosed tags without End Tag, Unknown Closing Tag, These are very sensitive for Browser Compatibly Issues, Page Loading Time and Web Page Optimization

We can able to keep our Web pages keep away from Unnecessary things such Comments, Un closed Tags, Un closed End Tags using HTML Tidy Object from PHP.

Here is the Example Code for PHP tidy Object. with Examples.
With this Example We have to use tidy Object (Tidy Object need to Enabled in PHP Configuration).
Check with phpinfo() under Tidy. ob_get_clean() , parse HTML String with parseString() function from Tidy object, and Clean our HTML with cleanRepair()