zegl/dson-php

PHP 的 DSON 编码和解码器

1.0.2 2014-06-08 20:40 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:17:47 UTC


README

PHP 的 DSON 编码/解码器

Doge

什么是 dson-php?

dson-php 是一个简单的 DSON http://dogeon.org 编码和解码器。它是一个纯 PHP 实现,不依赖于任何特殊库。

如何使用?

DSON::encode($in)

$example = array(
    "many" => "wow",
    "such" => array("foo", "doge", "inu")
);

echo DSON::encode($example);
such "many" is "wow" ! "such" is so "foo" and "doge" and "inu" many wow

DSON::decode($str, $assoc = false)

$res = DSON::decode('such "many" is "wow" ! "such" is so "foo" and "doge" and "inu" many wow');
object(stdClass)#1 (2) {
  ["many"]=>
  string(3) "wow"
  ["such"]=>
  array(3) {
    [0]=>
    string(3) "foo"
    [1]=>
    string(4) "doge"
    [2]=>
    string(3) "inu"
  }
}

设置 $assoc = true 将生成关联数组输出,(与 https://php.ac.cn/json_decode 比较)

$res = DSON::decode('such "many" is "wow" ! "such" is so "foo" and "doge" and "inu" many wow', true);
array(2) {
  ["many"]=>
  string(3) "wow"
  ["such"]=>
  array(3) {
    [0]=>
    string(3) "foo"
    [1]=>
    string(4) "doge"
    [2]=>
    string(3) "inu"
  }
}