Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active May 17, 2018 07:04
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 chernjie/633cc5913c40e3816b25 to your computer and use it in GitHub Desktop.
Save chernjie/633cc5913c40e3816b25 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
// if no arguments, take input from stdin
$argc < 2 && array_push($argv, file_get_contents("php://stdin"));
array_shift($argv);
$output = array();
foreach ($argv as $arg)
{
$unserialize = @unserialize($arg);
if ($unserialize) {
array_push($output, $unserialize);
continue;
}
$url = parse_url($arg);
empty($url['query']) || parse_str($url['query'], $url['query']);
array_push($output, $url);
}
defined('JSON_PRETTY_PRINT') || define('JSON_PRETTY_PRINT', 128);
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment