2017 © Pedro Peláez
 

library neat_html

Pretty-print PHP objects and arrays in html, json etc.

image

perchten/neat_html

Pretty-print PHP objects and arrays in html, json etc.

  • Friday, August 15, 2014
  • by perchten
  • Repository
  • 2 Watchers
  • 4 Stars
  • 201 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 10 % Grown

The README.md

neat_html

Prettier html printing of php objects and arrays, (*1)

Installation

Via Composer

Neat_html is available on Packagist (perchten/neat_html) and as such is installable via Composer., (*2)

Add the following to your composer.json, (*3)

{
    "require": {s
        "perchten/neat_html": "1.*"
    }
}
Direct include

Clone or download from GitHub and include directly in your code:, (*4)

require_once "path/to/neat_html.php"

Usage

Simple neat_html
neat_html($somevar)

Will print $somevar into html as a <pre>-wrapped block formatted like JSON., (*5)

Return, Don't Print
$output = neat_html($somevar,true)

As with neat_html($somevar) except that the output is returned, captured in the $output variable and not printed., (*6)

Die Immediately After Debug Print
neat_html($somevar,"die")

Outputs the formatted $somevar and then dies., (*7)

Output as Html Comment
neat_html($somevar,"comment")

Outputs the formatted code in comment form. comments start <!--neat_html for easy searching., (*8)

Do not wrap in <pre> tags
neat_html($somevar,"nopre")

Outputs the formatted code without wrapping it in <pre> tags. Useful for console printing., (*9)

neat_html($somefileref,'include)

Takes $somefileref as a file reference and includes that file's contents. Obviously, if the included file uses undefined variables then it will fail., (*10)

Also, the file reference must be absolute. For convenience a truepath function is included to get the real path. (PHP's realpath() function is a bit buggy, so best not use that. see http://stackoverflow.com/questions/4049856/replace-phps-realpath). e.g., (*11)

neat_html(truepath($somefileref),'include')
Output in JSON (Handy For Ajax)
neat_html($somevar,'json')

Returns the object in json notation. Handy when debugging over ajax that expects a json response., (*12)

Output in PHP (Handy For Purists ;))
neat_html($somevar,'php')

Returns the object in php notation. This then uses the var_export function instead of print_r. So the returned values here can even be interpreted directly as php variables., (*13)

Multiple Arguments

You can also collect multiple arguments together in a second argument array as follows:, (*14)

neat_html($somevar,array("include","comment","return");

Or as a comma or space separated list:, (*15)

neat_html($somevar,"include, comment, return");

And, as of v1.2 you can even use dynamic arguments:, (*16)

neat_html($somevar,"include","comment","return");
var_dump
neat_html($somevar,'dump');

This will run all data manipulation on $somevar (including if it is a file include), and then var_dump the result in addition to outputting in any other specified formatting., (*17)

Defaults

You can set defaults at a global level if you find yourself repeating the same optional arguments all the time., (*18)

Neat_Html::setDefault($option);

Neat_Html::getDefaults();

Neat_Html::setDefaults($optionsArray);

Neat_Html::removeDefault($option);  
Enabling/Disabling

neat_html statements will run by default, but you can control this by switching the functionality on and off globally, and querying the current state., (*19)

Neat_Html::setOn() // switches this module on globally

Neat_Html::setOff() // switches this module off globally

Neat_Html::isOn() // return true if module is on, otherwise false

License

Neat_html is licensed under the MIT License - see the LICENSE file for details, (*20)

The Versions

15/08 2014

dev-master

9999999-dev https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html, json etc.

  Sources   Download

MIT

debug php json console html arrays comments objects print print_r var_dump pretty-print var_export

15/08 2014

1.4.1

1.4.1.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html, json etc.

  Sources   Download

MIT

debug php json console html arrays comments objects print print_r var_dump pretty-print var_export

15/08 2014

dev-objectchaining

dev-objectchaining https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html, json etc.

  Sources   Download

MIT

debug php json console html arrays comments objects print print_r var_dump pretty-print var_export

13/08 2014

1.4.0

1.4.0.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html, json etc.

  Sources   Download

MIT

debug php json console html arrays comments objects print print_r var_dump pretty-print var_export

13/08 2014

1.3.0

1.3.0.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html, json etc.

  Sources   Download

MIT

debug php json console html arrays comments objects print print_r var_dump pretty-print var_export

13/08 2014

1.2.0

1.2.0.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html.

  Sources   Download

MIT

console arrays objects print print_r pretty-print

10/06 2014

1.1.1

1.1.1.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html.

  Sources   Download

MIT

console arrays objects print print_r pretty-print

10/06 2014

1.1.0

1.1.0.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html.

  Sources   Download

MIT

console arrays objects print print_r pretty-print

14/05 2014

1.0.1

1.0.1.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html.

  Sources   Download

MIT

console arrays objects print print_r pretty-print

14/05 2014

1.0.0

1.0.0.0 https://github.com/perchten/neat_html

Pretty-print PHP objects and arrays in html.

  Sources   Download

MIT

console arrays objects print print_r pretty-print