note 68661 added to function.strip-tags

From: Date: Sat, 05 Aug 2006 19:33:27 +0000
Subject: note 68661 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-115573@lists.php.net to get a copy of this message
I think that the new function works, but don't remove PHP tags, only html!! <?php function theRealStripTags2($string) { $tam=strlen($string); // tam have number of cars the string $newstring=""; // newstring will be returned $tag=0; /* if tag = 0 => copy car from string to newstring if tag > 0 => don't copy. Found one or more '<' and need to search '>'. If we found 3 '<' need to find all the 3 '>' */ /* I am C programmer. walk in a string is natural for me and more efficient */ for ($i=0; $i < $tam; $i++){ // If I found one '<', $tag++ and continue whithout copy if ($string{$i} == '<'){ $tag++; continue; } // if I found '>', decrease $tag and continue if ($string{$i} == '>'){ if ($tag){ $tag--; } /* $tag never be negative. If string is "<b>test</b>>" (error, of course) $tag will stop in 0 */ continue; } // if $tag is 0, can copy if ($tag == 0){ $newstring .= $string{$i}; // simple copy, only one car } } return $newstring; } echo theRealStripTags2("<tag>test</tag>"); // return "test" ?> ---- Server IP: 66.163.161.117 Probable Submitter: 201.14.246.79 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/68661 Del: integrated -- https://master.php.net/note/delete/68661/integrated Del: useless -- https://master.php.net/note/delete/68661/useless Del: bad code -- https://master.php.net/note/delete/68661/bad+code Del: spam -- https://master.php.net/note/delete/68661/spam Del: non-english -- https://master.php.net/note/delete/68661/non-english Del: in docs -- https://master.php.net/note/delete/68661/in+docs Del: other reasons-- https://master.php.net/note/delete/68661 Reject -- https://master.php.net/note/reject/68661 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115573) next »