Golang 實現 PHP裏的 serialize() 、 unserialize()php
安裝html
1
|
go get -u github.com
/techleeone/gophp/serialize
|
用法git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
package main
import (
"fmt"
"github.com/techleeone/gophp/serialize"
)
func main() {
str := `a:1:{s:3:
"php"
;s:24:
"世界上最好的語言"
;}`
// unserialize() in php
out, _ := serialize.UnMarshal([]byte(str))
fmt.Println(out)
//map[php:世界上最好的語言]
// serialize() in php
jsonbyte, _ := serialize.Marshal(out)
fmt.Println(string(jsonbyte))
// a:1:{s:3:"php";s:24:"世界上最好的語言";}
}
|