Text Processing
PHP String Function: Text Processing
Categories:
sprintf()
sprintf(
string $format
,mixed ...$values
):string
Returns a string produced according to the formatting string format
.
vsprintf()
vsprintf(
string $format
,array $values
):string
Operates as sprintf()
but accepts an array of arguments
, rather than a variable number of arguments.
vsprintf("%04d-%02d-%02d", explode('-', '1988-8-1'));
Minify html output
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
'/<!--(.|\s)*?-->/' // Remove HTML comments
);
$replace = array(
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");