The Little Guy Posted June 7, 2012 Share Posted June 7, 2012 Currently I use this to "Minify" my html: $template = preg_replace("/\s\s+/", "", $template); $template = preg_replace("/\r|\n/isU", "", $template); $template = preg_replace("/\t/isU", "", $template); I just found an issue that I didn't think of when writing this, within textarea's that gets minified too. so all the places where a newline would be within the textarea is now gone and when putting default data into a textarea mulitline functionality is gone. What can I do to preserve newlines in the textarea, yet still minify? Quote Link to comment https://forums.phpfreaks.com/topic/263824-minify-html-issue/ Share on other sites More sharing options...
requinix Posted June 7, 2012 Share Posted June 7, 2012 Use DOM to rewrite the HTML. It's not just textareas you have to treat specially: there's scripts, styles, and PREs for starters. And inline CSS is worth mentioning. Oh, and you're removing \s\s+? So if I type two spaces and/or newlines somewhere they're both lost? Quote Link to comment https://forums.phpfreaks.com/topic/263824-minify-html-issue/#findComment-1351935 Share on other sites More sharing options...
The Little Guy Posted June 7, 2012 Author Share Posted June 7, 2012 The CSS and JS I do want minified, so I don't care if they are, just can't use single line comments in the source. Okay, just input areas I would like to ignore (textarea/input) Quote Link to comment https://forums.phpfreaks.com/topic/263824-minify-html-issue/#findComment-1351948 Share on other sites More sharing options...
requinix Posted June 7, 2012 Share Posted June 7, 2012 I'm saying that the minimizing will break code like function update(v) { document.getElementById('id').value = v document.getElementById('other').value = v } as well as styles like body p { text-decoration: blink; } style="border: 2px solid blue" Quote Link to comment https://forums.phpfreaks.com/topic/263824-minify-html-issue/#findComment-1351985 Share on other sites More sharing options...
The Little Guy Posted June 8, 2012 Author Share Posted June 8, 2012 I guess with the "\s\s+" I could remove all space into 1 space, so that wouldn't break. But we have been going though code making sure there are semi-colons on everything in the js. I feel, if you can't minify js and css without errors (after comments are removed) then your doing something wrong. Quote Link to comment https://forums.phpfreaks.com/topic/263824-minify-html-issue/#findComment-1352190 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.