note 68641 deleted from function.strip-tags by danbrown

From: Date: Sun, 17 May 2009 16:00:04 +0000
Subject: note 68641 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154735@lists.php.net to get a copy of this message
Note Submitter: elgios at gmail dot com ---- I think that new function works. function theRealStripTags2($string) { $tam=strlen($string); // tam have number of cars the string $newstring=""; // newstring will be returned $tag=0; /* tag = 0 => copy car from string to newstring tag > 0 => don't copy. Find one or mor tag '<' and need to find '>'. If we find 3 '<' need to find all 3 '>' */ /* I am C programm. seek in a string is natural for me and more efficient Problem: copy a string to another string is more efficient but use more memory!!! */ for ($i=0; $i < $tam; $i++){ /* If I find one '<', $tag++ and continue whithout copy*/ if ($string{$i} == '<'){ $tag++; continue; } /* if I find '>', decrease $tag and continue */ if ($string{$i} == '>'){ if ($tag){ $tag--; } /* $tag never be negative. If string is "<b>test</b>>" (error, of course) $tag stop in 0 */ continue; } /* if $tag is 0, can copy */ if ($tag == 0){ $newstring .= $string{$i}; // simple copy, only car } } return $newstring; }

« previous php.notes (#154735) next »