note 67143 added to function.preg-match-all

From: Date: Sat, 03 Jun 2006 21:41:55 +0000
Subject: note 67143 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-113158@lists.php.net to get a copy of this message
<? function autoCloseTags($string) { // automatically close HTML-Tags // (usefull e.g. if you want to extract part of a blog entry or news as preview/teaser) // coded by Constantin Gross <connum at googlemail dot com> / 3rd of June, 2006 // feel free to leave comments or to improve this function! $donotclose=array('br','img','input'); //Tags that are not to be closed //prepare vars and arrays $tagstoclose=''; $tags=array(); //put all opened tags into an array preg_match_all("/<(([A-Z]|[a-z]).*)(( )|(>))/isU",$string,$result); $openedtags=$result[1]; $openedtags=array_reverse($openedtags); //this is just done so that the order of the closed tags in the end will be better //put all closed tags into an array preg_match_all("/<\/(([A-Z]|[a-z]).*)(( )|(>))/isU",$string,$result2); $closedtags=$result2[1]; //look up which tags still have to be closed and put them in an array for ($i=0;$i<count($openedtags);$i++) { if (in_array($openedtags[$i],$closedtags)) { unset($closedtags[array_search($openedtags[$i],$closedtags)]); } else array_push($tags, $openedtags[$i]); } $tags=array_reverse($tags); //now this reversion is done again for a better order of close-tags //prepare the close-tags for output for($x=0;$x<count($tags);$x++) { $add=strtolower(trim($tags[$x])); if(!in_array($add,$donotclose)) $tagstoclose.='</'.$add.'>'; } //and finally return $tagstoclose; } ?> ---- Server IP: 217.160.72.57 Probable Submitter: 84.163.77.204 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- http://master.php.net/note/edit/67143 Del: integrated -- http://master.php.net/note/delete/67143/integrated Del: useless -- http://master.php.net/note/delete/67143/useless Del: bad code -- http://master.php.net/note/delete/67143/bad+code Del: spam -- http://master.php.net/note/delete/67143/spam Del: non-english -- http://master.php.net/note/delete/67143/non-english Del: in docs -- http://master.php.net/note/delete/67143/in+docs Del: other reasons-- http://master.php.net/note/delete/67143 Reject -- http://master.php.net/note/reject/67143 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#113158) next »