psShrinkSource() Shrinks an HTML source string
Description:
I wanted to remove a lot of unwanted chrs, spaces, tabs, newlines, etc from a web page source. so I came up with this function.
Usage:
$buffer = psShrinkSource($buffer);
Example:
$buffer = psShrinkSource("<HTML> <BODY> <BR> <BR> </BODY> </HTML>"); // returns "<HTML><BODY><BR><BR></BODY></HTML>"
Code:
function psShrinkSource($buffer) { $buffer = preg_replace('/\s\s+/', ' ', $buffer); // excess white space $buffer = preg_replace('/^[ \t\r\n]+/m', '', $buffer); $buffer = str_replace("> <meta","><meta",$buffer); $buffer = str_replace(" <BR>","<BR>",$buffer); $buffer = str_replace("<BR> ","<BR>",$buffer); $buffer = str_replace(" <DIV","<DIV",$buffer);
return $buffer; }
Changlelog:
|
|