note 76417 added to ref.xml

From: Date: Sat, 14 Jul 2007 03:04:32 +0000
Subject: note 76417 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-128513@lists.php.net to get a copy of this message
I needed this for work/personal use. Sometimes you'll have a XML string generated as one long string and no line breaks...nusoap in the case of today/work, but there are any other number of possible things that will generate these. Anyways, this simply takes a long XML string and returns an indented/line-breaked version of the string for display/readability. <? function xmlIndent($str){ $ret = ""; $indent = 0; $indentInc = 3; $noIndent = false; while(($l = strpos($str,"<",$i))!==false){ if($l!=$r && $indent>0){ $ret .= "\n" . str_repeat(" ",$indent) . substr($str,$r,($l-$r)); } $i = $l+1; $r = strpos($str,">",$i)+1; $t = substr($str,$l,($r-$l)); if(strpos($t,"/")==1){ $indent -= $indentInc; $noIndent = true; } else if(($r-$l-strpos($t,"/"))==2 || substr($t,0,2)=="<?"){ $noIndent = true; } if($indent<0){ $indent = 0; } if($ret){ $ret .= "\n"; } $ret .= str_repeat(" ",$indent); $ret .= $t; if(!$noIndent){ $indent += $indentInc; } $noIndent = false; } $ret .= "\n"; return($ret); } ?> (...this was only tested for what i needed at work, could POSSIBLY need additions) ---- Server IP: 208.69.120.35 Probable Submitter: 68.53.192.143 ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- https://master.php.net/note/edit/76417 Del: integrated -- https://master.php.net/note/delete/76417/integrated Del: useless -- https://master.php.net/note/delete/76417/useless Del: bad code -- https://master.php.net/note/delete/76417/bad+code Del: spam -- https://master.php.net/note/delete/76417/spam Del: non-english -- https://master.php.net/note/delete/76417/non-english Del: in docs -- https://master.php.net/note/delete/76417/in+docs Del: other reasons-- https://master.php.net/note/delete/76417 Reject -- https://master.php.net/note/reject/76417 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128513) next »