Jump to content

Recommended Posts

The way i create my pages is: i put all the outgoing html into a variable and then at the end echo it all out. I had an idea the other day, I bet there is a function, class, or script, which takes html and cleans it up so its readable for humans. Ex:

<?php
$body ="<html><head></head><body><div></div></body></html>";
$body = html_cleanup($body);
echo $body;
//should output
?>
<html>
   <head>
   </head>
   <body>
      <div>
      </div>
   </body>
</html>

Im looking for the html_cleanup() function. just wondering if anyone does the same and what they do. Or if they dont like the idea and why they dont. Thanks

Link to comment
https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/
Share on other sites

here is a function to do this btw. I figure if someone comes across this thread in a search or something i would make it easier for them

 

//tidy function based on php.net example. Code has not been tested.
function html_cleanup($html)
{
$config = array(
            'indent'         => true,
            'output-xml'     => true,
            'input-xml'     => true,
            'wrap'         => '1000');

$tidy = new tidy();
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
return tidy_get_output($tidy);
}

here is a function to do this btw. I figure if someone comes across this thread in a search or something i would make it easier for them

 

//tidy function based on php.net example. Code has not been tested.
function html_cleanup($html)
{
$config = array(
            'indent'         => true,
            'output-xml'     => true,
            'input-xml'     => true,
            'wrap'         => '1000');

$tidy = new tidy();
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
return tidy_get_output($tidy);
}

 

Can you post the output? or the results are the same like in the above codeT

on of the uses would be for employers looking and my work and deciding if they want to hire me or not... thats the main one i can think of right now, but im sure there is another one.... just escaping me.

 

Ill try that function in a minute logovendor and give you my results

that function works for me.

 

<?php
//html.php
function html_cleanup($html)
{
$config = array(
			'indent'         => true,
			'output-xml'     => true,
			'input-xml'     => true,
			'wrap'         => '1000');

$tidy = new tidy();
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
return tidy_get_output($tidy);
}
	$html = "<html><head></head><body><div><p>some text</p></div></body></html>";
	$html2 = html_cleanup($html);
        echo "<!--Without html cleanup-->\n".$html;
	echo "\n\n<!--With html cleanup-->\n".$html2;
?>

here are the results

<!--Without html cleanup-->
<html><head></head><body><div><p>some text</p></div></body></html>

<!--With html cleanup-->
<html>
  <head></head>
  <body>
    <div>
      <p>some text</p>
    </div>

  </body>
</html>

 

I put it online as well so if you really want to go check its @ http://grizz.ericwooley.com/html.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.