golang实现php里的serialize()和unserialize()序列和反序列方法

Golang 实现 PHP里的 serialize() 、 unserialize()

安装


go get -u github.com/techleeone/gophp/serialize

用法

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:"世界上最好的语言";}

}


<p>github地址:<a href="https://github.com/techleeone/gophp" rel="nofollow noreferrer">https://github.com/techleeone...</a></p>

                
                                                
原文地址:https://segmentfault.com/a/1190000016818544
posted @ 2018-11-15 16:07  sfornt  阅读(504)  评论(0编辑  收藏  举报