note 73939 added to function.ob-start

From: Date: Fri, 16 Mar 2007 10:05:16 +0000
Subject: note 73939 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-124506@lists.php.net to get a copy of this message
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 &nbsp; $buffer = str_replace(" &nbsp;", "&nbsp;", $buffer); $buffer = str_replace("&nbsp; ", "&nbsp;", $buffer); return $buffer; } ob_start("stripBufferSkipTextareaTags"); ?> ---- Server IP: 83.64.128.68 Probable Submitter: 83.18.122.186 (proxied: 195.140.153.125) ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- https://master.php.net/note/edit/73939 Del: integrated -- https://master.php.net/note/delete/73939/integrated Del: useless -- https://master.php.net/note/delete/73939/useless Del: bad code -- https://master.php.net/note/delete/73939/bad+code Del: spam -- https://master.php.net/note/delete/73939/spam Del: non-english -- https://master.php.net/note/delete/73939/non-english Del: in docs -- https://master.php.net/note/delete/73939/in+docs Del: other reasons-- https://master.php.net/note/delete/73939 Reject -- https://master.php.net/note/reject/73939 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124506) next »