Source Code:
(back to article)
<?php $html = ' <html> <head> <title>My Page</title> </head> <body> <h1>Hello, World!</h1> </body> </html>'; // Remove extra whitespace from beginning and end of HTML code $html = trim($html); // Remove extra whitespace between HTML tags $html = preg_replace('/\s+/', ' ', $html); // Remove extra lines $html = preg_replace('/\n+/', '', $html); // Remove spaces between opening and closing HTML tags $html = preg_replace('/>\\s+</', '><', $html); echo $html;
Result:
Report an issue