summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--urlencode.c20
-rw-r--r--urlencode.php6
2 files changed, 20 insertions, 6 deletions
diff --git a/urlencode.c b/urlencode.c
new file mode 100644
index 0000000..a8c61ad
--- /dev/null
+++ b/urlencode.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2015 Luke Shumaker <lukeshu@sbcglobal.net> */
+#include <stdio.h>
+
+int
+main () {
+ int c;
+ while ((c = getchar()) != EOF) {
+ if (('0' <= c && c <= '9')
+ || ('A' <= c && c <= 'Z')
+ || ('a' <= c && c <= 'z')
+ ){
+ putchar(c);
+ } else if (c == ' ') {
+ putchar('+');
+ } else {
+ printf("%%%02X", c);
+ }
+ }
+ return 0;
+}
diff --git a/urlencode.php b/urlencode.php
deleted file mode 100644
index c40263d..0000000
--- a/urlencode.php
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/php -n
-<?php
-# Copyright (C) 2011, 2014 Luke Shumaker <lukeshu@sbcglobal.net>
-
-$contents = file_get_contents('php://stdin');
-echo urlencode($contents);