PHP Minify echo Output

/* Be careful not to use single line comments in your output, i.e., // comments */ echo str_replace(["\r\n", "\n", "\t"], '', <<<HTML <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head prefix="og: http://ogp.me/ns# object: http://ogp.me/ns/object#"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="MobileOptimized" content="320"> <!-- You get the idea here ... --> HTML );
Works with all output, not just HTML.

Outputs minified text as a concatenated string to the browser. All of what is there would be a single line like this (no line breaks or tabs in HTML source):

<html xmlns=" http://www.w3.org/1999/xhtml" lang="en"><head prefix="og: http://ogp.me/ns# object: http://ogp.me/ns/object#"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="MobileOptimized" content="320"><!-- You get the idea here ... -->

/* Be careful not to use single line comments in your output, i.e., // comments */

This is using HEREDOC syntax in PHP. Make sure you put the "HTML" in all caps and on the first column in the line for it to work. More info on the syntax here:

http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.