Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c01b20f

Browse files
author
Mathieu Ferment
committed
Add explode_url.php script
0 parents commit c01b20f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

‎Util/TextColorWriter.php‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* Text Color Writer
5+
*
6+
* Thanks Thijs Lensselink
7+
* @link http://blog.lenss.nl/2012/05/adding-colors-to-php-cli-script-output/
8+
*/
9+
class TextColorWriter
10+
{
11+
const BASH_PROMPT_BLACK = 30;
12+
const BASH_PROMPT_RED = 31;
13+
const BASH_PROMPT_GREEN = 32;
14+
const BASH_PROMPT_YELLOW = 33;
15+
const BASH_PROMPT_BLUE = 34;
16+
const BASH_PROMPT_WHITE = 37;
17+
18+
static public function textColor($string, $colorID)
19+
{
20+
if (!in_array($colorID, static::getKnownColors())) {
21+
throw new Exception("Error unknown color ID $colorID");
22+
}
23+
24+
$colorChar = "033円[".$colorID."m";
25+
$coloredString = $colorChar . $string . "033円[0m";
26+
return $coloredString;
27+
}
28+
29+
private function getKnownColors()
30+
{
31+
$colors = array(
32+
static::BASH_PROMPT_BLACK,
33+
static::BASH_PROMPT_RED,
34+
static::BASH_PROMPT_GREEN,
35+
static::BASH_PROMPT_YELLOW,
36+
static::BASH_PROMPT_BLUE,
37+
static::BASH_PROMPT_WHITE
38+
);
39+
40+
return $colors;
41+
}
42+
}

‎explore_url.php‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* Explode Url
5+
*
6+
* Explode an URL and display its elements
7+
*/
8+
9+
if (count($argv) !== 2) {
10+
echo 'php explore_url <url>' . PHP_EOL;
11+
die(1);
12+
}
13+
14+
require 'Util/TextColorWriter.php';
15+
16+
$url = $argv[1];
17+
$GETParts = explode('&', $url);
18+
$pathParts = explode('?', $GETParts[0]);
19+
20+
if (count($pathParts) !== 2) {
21+
throw new Exception("Error while parsing url");
22+
}
23+
24+
$path = $pathParts[0];
25+
$firstParameter = $GETParts[1];
26+
27+
echo TextColorWriter::textColor('URL ANALYSIS:', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
28+
echo TextColorWriter::textColor('Path:', TextColorWriter::BASH_PROMPT_BLUE). ''. $path . PHP_EOL;
29+
echo TextColorWriter::textColor('GET parameters:', TextColorWriter::BASH_PROMPT_BLUE). PHP_EOL;
30+
echo ' * ' . $firstParameter . PHP_EOL;
31+
foreach ($pathParts as $parameter) {
32+
echo ' * ' . $parameter . PHP_EOL;
33+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /