如何优化我的HTML代码

i have been saving buffer content in a mysql text field , but when content exceeded the number of characters limit, code is crunched.

so how can i optimize html buffer content by removing tabs and white spaces from the code using php ?

Why don't you use a type able to keep all your data? E.g. LONGTEXT or MEDIUMTEXT? You can however strip away all repetition of space character using

preg_replace("/\s+/", " ", trim($s));

ADD

As noticed in comments, this will crunch every repeated "space" character even when it's meaningful. This won't work with default pre tag style, and with any other tag with CSS that changes the white-space attribute.

You could use a regular expression like:

preg_replace("/\s+/", " ", $string);

That should replace all multiple white-spaces, tabs and new-lines with just one.

See also: How do I remove extra spaces, tabs and line feeds from a sentence and substitute them with just one space?

You could compress the data with a function such as gzdeflate. See http://php.net/manual/en/function.gzdeflate.php

If this needs to go into a non-binary safe location, you could base64_encode the gzipped string, and store afterwards.