gophp

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 3 Imported by: 0

README

gophp

Golang implementation for PHP's functions

Install / Update

go get -u github.com/techleeone/gophp

Example

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

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LessValue

func LessValue(a, b reflect.Value) bool

lessValue compares two reflect.Value instances and returns true if a is considered to be less than b.

This function is used to sort keys for what amounts to associate arrays and objects in PHP. These are represented as slices and maps in Go. Since Go randomised map iterators we need to make sure we always return the keys of an associative array or object in a predicable order.

The keys can be numerical, strings or a combination of both. We treat numbers (integers, unsigned integers and floats) as always less than strings. Numbers are ordered by magnitude (ignoring types) and strings are orders lexicographically.

If keys are of any other type the behavior of the comparison is undefined. If there is a legitimate reason why keys could be other types then this function should be updated accordingly.

func LowerCaseFirstLetter

func LowerCaseFirstLetter(s string) string

func NumericalToString

func NumericalToString(value interface{}) (string, bool)

func NumericalValue

func NumericalValue(value reflect.Value) (float64, bool)

numericalValue returns the float64 representation of a value if it is a numerical type - integer, unsigned integer or float. If the value is not a numerical type then the second argument is false and the value returned should be disregarded.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL