thewooleymammoth Posted May 19, 2010 Share Posted May 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/ Share on other sites More sharing options...
trq Posted May 19, 2010 Share Posted May 19, 2010 tidy. I wouldn't bother in production, though it can come in handy during dev. Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060362 Share on other sites More sharing options...
thewooleymammoth Posted May 19, 2010 Author Share Posted May 19, 2010 cool, thanks. Why not in production? Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060363 Share on other sites More sharing options...
trq Posted May 19, 2010 Share Posted May 19, 2010 Its pretty slow for starters + really, adding all that nice formatting makes your response just that little bit larger. Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060365 Share on other sites More sharing options...
thewooleymammoth Posted May 19, 2010 Author Share Posted May 19, 2010 is it worth it in production if you use caching? Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060367 Share on other sites More sharing options...
thewooleymammoth Posted May 19, 2010 Author Share Posted May 19, 2010 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); } Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060373 Share on other sites More sharing options...
Philip Posted May 19, 2010 Share Posted May 19, 2010 What is the use of tidying it in production? So those few people that care to look at the source code go "oh thats so nice and pretty!" ? It's pretty much a waste of resources outside dev, like Daniel said. Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060537 Share on other sites More sharing options...
LogoVendor Posted May 19, 2010 Share Posted May 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060594 Share on other sites More sharing options...
thewooleymammoth Posted May 19, 2010 Author Share Posted May 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060625 Share on other sites More sharing options...
thewooleymammoth Posted May 19, 2010 Author Share Posted May 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060632 Share on other sites More sharing options...
Daniel0 Posted May 19, 2010 Share Posted May 19, 2010 It's pretty much a waste of resources outside dev, like Daniel said. Wasn't me, but Tony Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060637 Share on other sites More sharing options...
Philip Posted May 19, 2010 Share Posted May 19, 2010 It's pretty much a waste of resources outside dev, like Daniel thorpe said. Wasn't me, but Tony Oops, just saw a red badge! Look what I get for assuming Quote Link to comment https://forums.phpfreaks.com/topic/202223-html-source-code-cleanup/#findComment-1060671 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.