Liking cljdoc? Tell your friends :D

php-clj Build Status

A Clojure library to deserialize PHP as generated by serialize into Clojure data structures and vice versa.

Current version: 0.4.1
Supported Clojure versions: 1.4, 1.5, 1.5.1


  (:require [php_clj.core :refer [php->clj clj->php]]))

(php->clj "s:18:\"Café Scientifique\";")
;; => "Café Scientifique"

(php->clj "i:1337;")
;; => 1337

(php->clj "a:2:{s:4:\"Wöo\";a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}s:3:\"Bar\";b:0;}")
;; => #ordered/map (["Wöo" [1 2 3]] ["Bar" false])

(clj->php "Café")
;; => "s:5:\"Café\";"

(clj->php {"name" "Bob"})
;; => "a:1:{s:4:\"name\";s:3:\"Bob\";}"

A Note on PHP Arrays

As PHP's Arrays are actually ordered maps, converting an array such as:

    "name" => "Bob",
    "age" => 42

Will result in an ordered map equivalent to the following:

{"name" "Bob", "age" 42}

Note that Clojure's standard map implementation does not retain insertion order (and ArrayMaps are only suitable for "very small maps") hence the use of the ordered-map type.

Arrays with consecutive indices starting at 0 such as

    0 => "a",
    1 => "b",
    2 => "c"

Will be converted into vectors like so:

["a" "b" "c"]


php-clj is available on Clojars, add the following to your Leiningen dependencies:

[php-clj "0.4.1"]



Copyright © 2014 Paul Mucur.

Distributed under the Eclipse Public License.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close