Is there a pretty print for PHP?
This is what I use to print my arrays: <pre> <?php print_r($your_array); ?> </pre> The magic comes with the pre tag.
This is what I use to print my arrays: <pre> <?php print_r($your_array); ?> </pre> The magic comes with the pre tag.
The trick is to pass a string as the indent and to treat the last child specially: class Node { public void PrintPretty(string indent, bool last) { Console.Write(indent); if (last) { Console.Write(“\\-“); indent += ” “; } else { Console.Write(“|-“); indent += “| “; } Console.WriteLine(Name); for (int i = 0; i < Children.Count; i++) … Read more
JSON.stringify takes more optional arguments. Try: JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, 4); // Indented 4 spaces JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, “\t”); // Indented with tab From: How can I beautify JSON programmatically? Should work in modern browsers, and it is included in json2.js if you need a fallback for browsers that don’t support the JSON helper functions. For display purposes, … Read more
After months of research I’ve come up with this. Public Function PrettyPrintXML(XML As String) As String Dim Reader As New SAXXMLReader60 Dim Writer As New MXXMLWriter60 Writer.indent = True Writer.standalone = False Writer.omitXMLDeclaration = False Writer.encoding = “utf-8” Set Reader.contentHandler = Writer Set Reader.dtdHandler = Writer Set Reader.errorHandler = Writer Call Reader.putProperty(“http://xml.org/sax/properties/declaration-handler”, _ Writer) Call … Read more
The missing part is the amount to indent. You can set the indentation and indent amount as follow: transformer.setOutputProperty(OutputKeys.INDENT, “yes”); transformer.setOutputProperty(“{http://xml.apache.org/xslt}indent-amount”, “2”); transformer.transform(xmlInput, xmlOutput);
Please use a <pre> tag demo : http://jsfiddle.net/K83cK/ var data = { “data”: { “x”: “1”, “y”: “1”, “url”: “http://url.com” }, “event”: “start”, “show”: 1, “id”: 50 } document.getElementById(“json”).textContent = JSON.stringify(data, undefined, 2); <pre id=”json”></pre>
The answer by @mislav is somewhat wrong. Nokogiri does support pretty-printing if you: Parse the document as XML Instruct Nokogiri to ignore whitespace-only nodes (“blanks”) during parsing Use to_xhtml or to_xml to specify pretty-printing parameters In action: html=”<section> <h1>Main Section 1</h1><p>Intro</p> <section> <h2>Subhead 1.1</h2><p>Meat</p><p>MOAR MEAT</p> </section><section> <h2>Subhead 1.2</h2><p>Meat</p> </section></section>” require ‘nokogiri’ doc = Nokogiri::XML(html,&:noblanks) puts … Read more
The + x coerces the object x into a string, which is just [object Object]: http://jsfiddle.net/Ze32g/ The pretty printing is a very nice and probably very complex underlying code that someone implemented as part of the console object and the log method. Try this: console.log(“hmm: “, x);
You can specify a width on string fields, e.g. printf(“%-20s”, “initialization…”); And then whatever’s printed with that field will be blank-padded to the width you indicate. The – left-justifies your text in that field.
I seem to be having good output with prettytable: from prettytable import PrettyTable x = PrettyTable(dat.dtype.names) for row in dat: x.add_row(row) # Change some column alignments; default was ‘c’ x.align[‘column_one’] = ‘r’ x.align[‘col_two’] = ‘r’ x.align[‘column_3’] = ‘l’ And the output is not bad. There is even a border switch, among a few other options: … Read more