https://github.com/elliotchance/phpserialize
📑 PHP serialize() and unserialize() for Go
https://github.com/elliotchance/phpserialize
encoding go php
Last synced: 6 months ago
JSON representation
📑 PHP serialize() and unserialize() for Go
- Host: GitHub
- URL: https://github.com/elliotchance/phpserialize
- Owner: elliotchance
- License: mit
- Created: 2017-07-04T11:32:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-31T15:17:15.000Z (over 1 year ago)
- Last Synced: 2025-03-30T09:09:51.993Z (6 months ago)
- Topics: encoding, go, php
- Language: Go
- Homepage:
- Size: 60.5 KB
- Stars: 126
- Watchers: 4
- Forks: 40
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/elliotchance/phpserialize)
PHP [serialize()](http://php.net/manual/en/function.serialize.php) and
[unserialize()](http://php.net/manual/en/function.unserialize.php) for Go.# Install / Update
```bash
go get -u github.com/elliotchance/phpserialize
````phpserialize` requires Go 1.8+.
# Example
```go
package mainimport (
"fmt"
"github.com/elliotchance/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
```go
package mainimport (
"fmt"
"github.com/elliotchance/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)
}
```