Last active
April 21, 2016 05:36
-
-
Save yoander/7b9821ad5d077dc88cc29e1ab031ea0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
// Check the scripts is called with arguments | |
if (empty($argv[1])) { | |
die('You must specify a file!'); | |
} | |
// Set the file name | |
$file = $argv[1]; | |
// Verify if filename exists | |
if (!is_readable($file)) { | |
die('File is missing or is not readable!'); | |
} | |
// Get the file content | |
$content = file_get_contents($file); | |
// Verify the content is not empty | |
if (empty($content)) { | |
die('File is empty nothing to do ;)'); | |
} | |
// Decode html entities | |
$content = html_entity_decode($content); | |
// Parse the xml and format it | |
$doc = new DOMDocument(); | |
$doc->preserveWhiteSpace = false; | |
$doc->formatOutput = true; | |
$doc->loadXML($content); | |
// Print the result | |
echo $doc->saveXML(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment