note 83460 added to function.highlight-string

From: Date: Tue, 27 May 2008 11:04:58 +0000
Subject: note 83460 added to function.highlight-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-139843@lists.php.net to get a copy of this message
Here is an improved version of Dimitry's xml_highlight function. I fixed a bug which replaced the first character of the tags name, and added a line to replace the tabs and spaces with non-breaking space symbols to keep the identation. <? function xml_highlight($s){ $s = preg_replace("|<([^/?])(.*)\s(.*)>|isU", "[1]<[2]\\1\\2[/2] [5]\\3[/5]>[/1]", $s); $s = preg_replace("|</(.*)>|isU", "[1]</[2]\\1[/2]>[/1]", $s); $s = preg_replace("|<\?(.*)\?>|isU","[3]<?\\1?>[/3]", $s); $s = preg_replace("|\=\"(.*)\"|isU", "[6]=[/6][4]\"\\1\"[/4]",$s); $s = htmlspecialchars($s); $s = str_replace("\t","&nbsp;&nbsp;",$s); $s = str_replace(" ","&nbsp;",$s); $replace = array(1=>'0000FF', 2=>'0000FF', 3=>'800000', 4=>'FF00FF', 5=>'FF0000', 6=>'0000FF'); foreach($replace as $k=>$v) { $s = preg_replace("|\[".$k."\](.*)\[/".$k."\]|isU", "<font color=\"#".$v."\">\\1</font>", $s); } return nl2br($s); } ?> ---- Server IP: 217.75.128.29 Probable Submitter: 213.91.217.3 ---- Manual Page -- http://www.php.net/manual/en/function.highlight-string.php Edit -- https://master.php.net/note/edit/83460 Del: integrated -- https://master.php.net/note/delete/83460/integrated Del: useless -- https://master.php.net/note/delete/83460/useless Del: bad code -- https://master.php.net/note/delete/83460/bad+code Del: spam -- https://master.php.net/note/delete/83460/spam Del: non-english -- https://master.php.net/note/delete/83460/non-english Del: in docs -- https://master.php.net/note/delete/83460/in+docs Del: other reasons-- https://master.php.net/note/delete/83460 Reject -- https://master.php.net/note/reject/83460 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139843) next »