Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Go (golang) package for working with PHP serialization.

License

Notifications You must be signed in to change notification settings

writeas/phpserialize

Repository files navigation

Build Status

PHP serialize() and unserialize() for Go.

Install / Update

go get -u github.com/writeas/phpserialize

phpserialize requires Go 1.8+.

Example

package main
import (
	"fmt"
	"github.com/writeas/phpserialize"
)
func main() {
	out, err := phpserialize.Marshal(3.2, nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(out))
	var in float64
	err = phpserialize.Unmarshal(out, &in)
	fmt.Println(in)
}

Using struct field tags for marshalling

package main
import (
	"fmt"
	"github.com/writeas/phpserialize"
)
type MyStruct struct {
	// Will be marhsalled as my_purpose
	MyPurpose string `php:"my_purpose"`
	// Will be marshalled as my_motto, and only if not a nil pointer
	MyMotto *string `php:"my_motto,omitnilptr"`
	// Will not be marshalled
	MySecret string `php:"-"`
}
func main() {
	my := MyStruct{
		MyPurpose: "No purpose",
		MySecret: "Has a purpose",
	}
	out, err := phpserialize.Marshal(my, nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(out)
}

About

A Go (golang) package for working with PHP serialization.

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • Go 100.0%

AltStyle によって変換されたページ (->オリジナル) /