note 73939 deleted from function.ob-start by cmb
| From: | cmb@php.net | Date: | Sun, 14 Jul 2019 11:28:14 +0000 |
| Subject: | note 73939 deleted from function.ob-start by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211577@lists.php.net to get a copy of this message | ||
Note Submitter: joebezucha at tlen dot pl
----
Hi, I use those functions for stripping unnecessary chars in my output code...because I have
JavaScript placed in outpout code so I don't remove \n\r\t but just replace them with single
space (it could cause errors in scripts)
Function stripBufferSkipTextareaTags skips tags Textarea. It's needed to don't loose \n\r
when user edit some content...
sorry for my english ;)
<?php
function stripBufferSkipTextareaTags($buffer){
$poz_current = 0;
$poz_end = strlen($buffer)-1;
$result = "";
while ($poz_current < $poz_end){
$t_poz_start = stripos($buffer, "<textarea", $poz_current);
if ($t_poz_start === false){
$buffer_part_2strip = substr($buffer, $poz_current);
$temp = stripBuffer($buffer_part_2strip);
$result .= $temp;
$poz_current = $poz_end;
}
else{
$buffer_part_2strip = substr($buffer, $poz_current, $t_poz_start-$poz_current);
$temp = stripBuffer($buffer_part_2strip);
$result .= $temp;
$t_poz_end = stripos($buffer, "</textarea>", $t_poz_start);
$temp = substr($buffer, $t_poz_start, $t_poz_end-$t_poz_start);
$result .= $temp;
$poz_current = $t_poz_end;
}
}
return $result;
}
function stripBuffer($buffer){
// change new lines and tabs to single spaces
$buffer = str_replace(array("\r\n", "\r", "\n", "\t"),
' ', $buffer);
// multispaces to single...
$buffer = ereg_replace(" {2,}", ' ',$buffer);
// remove single spaces between tags
$buffer = str_replace("> <", "><", $buffer);
// remove single spaces around
$buffer = str_replace(" ", " ", $buffer);
$buffer = str_replace(" ", " ", $buffer);
return $buffer;
}
ob_start("stripBufferSkipTextareaTags");
?>