pdp
Version:
Node.js parser of PHP var dumps
58 lines (45 loc) • 1.07 kB
Markdown
Node.js parser of PHP var dumps.
[](http://travis-ci.org/watson/pdp)
```
npm install pdp
```
Given a variable, the PHP function [print_r](http://www.php.net/print_r)
will print human-readable information about the variable. This is best
illustrated with an example:
```php
<pre>
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
</pre>
```
The above example will output:
```html
<pre>
Array
(
[] => apple
[] => banana
[] => Array
(
[] => x
[] => y
[] => z
)
)
</pre>
```
Feed the above output inside the `<pre>` tags to this module and you get
a nice JavaScript object literal or Array:
```javascript
var pdp = require('pdp');
var dump = '...'; // let's imagine we have the entire Array(...) dump here
console.log(pdp(dump)); // prints: { a: 'apple', b: 'banana', c: [ 'x', 'y', 'z' ] }
```
MIT