summaryrefslogtreecommitdiffstats
path: root/urldecode
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-07-20 15:24:07 +0200
committerFlorian Pritz <bluewind@xinu.at>2013-07-20 15:24:07 +0200
commit5bb9c57fdbfe6ee69c0ffaad52b9d4259a6b97f5 (patch)
treec5e0465d81ef97516888c173e9b9ab75b515ba9f /urldecode
parent934c2f85fa9c3b679d5c91bf8fc09272a2bec537 (diff)
downloadbin-5bb9c57fdbfe6ee69c0ffaad52b9d4259a6b97f5.tar.gz
bin-5bb9c57fdbfe6ee69c0ffaad52b9d4259a6b97f5.tar.xz
urldecode: rewrite in php
Faster than pure bash and simple enough. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'urldecode')
-rwxr-xr-xurldecode24
1 files changed, 9 insertions, 15 deletions
diff --git a/urldecode b/urldecode
index 19df702..dcea3e2 100755
--- a/urldecode
+++ b/urldecode
@@ -1,16 +1,10 @@
-#!/bin/bash
-arg="$1"
-i="0"
-while [ "$i" -lt ${#arg} ]; do
- c0=${arg:$i:1}
- if [ "x$c0" = "x%" ]; then
- c1=${arg:$((i+1)):1}
- c2=${arg:$((i+2)):1}
- printf "\x$c1$c2"
- i=$((i+3))
- else
- echo -n "$c0"
- i=$((i+1))
- fi
-done
+#!/usr/bin/php
+<?php
+if (count($argv) == 0) {
+ echo urldecode(file_get_contents("php://stdin"));
+} else {
+ foreach ($argv as $arg) {
+ echo urldecode(file_get_contents($arg));
+ }
+}