Skip to content

Commit dc1b9a8

Browse files
committed
Add PHP
1 parent 6d35e1c commit dc1b9a8

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

code-golf.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ func render(w http.ResponseWriter, tmpl *template.Template, vars map[string]inte
229229
func runCode(lang, code string) string {
230230
var out bytes.Buffer
231231

232+
if lang == "php" {
233+
code = "<?php " + code + " ?>"
234+
}
235+
232236
cmd := exec.Cmd{
233237
Dir: "containers/" + lang,
234238
Path: "../../run-container",

containers/php/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM alpine:edge
2+
3+
RUN apk add --no-cache curl gcc make musl-dev
4+
5+
RUN curl -L https://php.net/distributions/php-7.1.6.tar.xz | tar xJf -
6+
7+
RUN cd php-7.1.6 \
8+
&& ./configure \
9+
--disable-all \
10+
--disable-cgi \
11+
--prefix=/usr \
12+
--without-pear \
13+
&& make install
14+
15+
FROM scratch
16+
17+
COPY --from=0 /lib/ld-musl-x86_64.so.1 /lib/
18+
COPY --from=0 /usr/bin/php /usr/bin/
19+
20+
ENTRYPOINT ["/usr/bin/php"]

db.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,16 @@ func printLeaderboards(w http.ResponseWriter) {
109109

110110
i++
111111

112+
if lang == "php" {
113+
lang = "PHP"
114+
} else {
115+
lang = strings.Title(lang)
116+
}
117+
112118
w.Write([]byte(
113119
"<tr><td>" + ordinal(i) +
114120
"<td>" + strconv.Itoa(length) +
115-
"<td>" + strings.Title(lang) +
121+
"<td>" + lang +
116122
`<td><img src="//avatars.githubusercontent.com/` + login +
117123
`?size=20"> ` + login,
118124
))

0 commit comments

Comments
 (0)