Skip to content

Instantly share code, notes, and snippets.

@yoander
Last active April 21, 2016 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoander/7b9821ad5d077dc88cc29e1ab031ea0f to your computer and use it in GitHub Desktop.
Save yoander/7b9821ad5d077dc88cc29e1ab031ea0f to your computer and use it in GitHub Desktop.
#!/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