syyongx / php2go Goto Github PK
View Code? Open in Web Editor NEWUse Golang to implement PHP's common built-in functions.
License: MIT License
Use Golang to implement PHP's common built-in functions.
License: MIT License
defer syscall.Close(rawFd)
$ go get github.com/syyongx/php2go
syyongx\php2go\php_unix.go:11:9: undefined: syscall.Umask
syyongx\php2go\php_unix.go:16:8: undefined: syscall.Statfs_t
syyongx\php2go\php_unix.go:17:9: undefined: syscall.Statfs
syyongx\php2go\php_unix.go:26:8: undefined: syscall.Statfs_t
syyongx\php2go\php_unix.go:27:9: undefined: syscall.Statfs
Trim method is implemented incorrectly
The error "strconv.ParseInt: parsing "你好世界": invalid syntax" is returned while trying to run the test code below.
package main
import (
"fmt"
"strconv"
php "github.com/syyongx/php2go"
)
func Bin2hex(str string) (string, error) {
byteArray := []byte(str)
var out string;
for i:=0; i < len(byteArray); i++{
out += strconv.FormatInt(int64(byteArray[i]), 16)
}
return out,nil
}
func main() {
fmt.Println(Bin2hex("你好世界"))
fmt.Println(php.Bin2hex("你好世界"))
}
Results as follow.
C:\Users\Toby\Desktop\golang\fsadapt>fsadapt.exe
e4bda0e5a5bde4b896e7958c <nil>
strconv.ParseInt: parsing "你好世界": invalid syntax
System Information:
OS: Windows 7 64 bit
Go version: go version go1.13.4 windows/amd64
func Rand(min, max int) int {
if min > max {
panic("min: min cannot be greater than max")
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
n := r.Intn(math.MaxInt32)
return n/((math.MaxInt32+1)/(max-min+1)) + min
return 1
}
把加一去掉就可以了
λ go version
go version go1.7.3 windows/amd64
λ go get github.com/syyongx/php2go
# github.com/syyongx/php2go
D:\golangcode\src\github.com\syyongx\php2go\php.go:977: u.Hostname undefined (type *url.URL has no field or method Hostname)
D:\golangcode\src\github.com\syyongx\php2go\php.go:980: u.Port undefined (type *url.URL has no field or method Port)
D:\golangcode\src\github.com\syyongx\php2go\php.go:1589: undefined: syscall.Statfs_t
D:\golangcode\src\github.com\syyongx\php2go\php.go:1590: undefined: syscall.Statfs
D:\golangcode\src\github.com\syyongx\php2go\php.go:1600: undefined: syscall.Statfs_t
D:\golangcode\src\github.com\syyongx\php2go\php.go:1601: undefined: syscall.Statfs
D:\golangcode\src\github.com\syyongx\php2go\php.go:1615: undefined: syscall.Umask
Should there be a new structure, the map is defined to be ordered, so that array_value, array_combine and other functions are more accurate, rather than directly using map
round function in php have tow params,but in this pkg just only one param;It is can not return a decimal.
mysqli_real_escape_string
package main
import "github.com/syyongx/php2go"
import "fmt"
func main() {
s := "13000"
fmt.Printf("%s=>%s\n", s, php2go.Trim(s))
}
localhost:~$ go run a.go
13000=>13
rt
I have a library parsestr that emulates PHP's parse_str behaviour.
I just thought you may be interested to give it a look as you note that yours does not quite do the deed.
need function __call(), thans for you.
数组部分没有排序算法吗^_^
need function call_user_func_array( ), thans for you.
var testNull interface{}
fmt.Println(php2go.Empty(testNull))
hello:reflect: call of reflect.Value.Type on zero Value
TestTime test fails with go 1.14.2 in UTC+1 timezone.
$ go version
go version go1.14.2 linux/amd64
$ go test -v
=== RUN TestTime
TestTime: php_test.go:312: Expected 27/04/2018 11:23:14 AM (type string) - Got 27/04/2018 04:23:14 AM (type string)
--- FAIL: TestTime (0.00s)
$
The reason is likely that time.Unix() uses local time input, which means that test will faily every time it is run outside of author's timezone.
Test:
equal(t, "27/04/2018 11:23:14 AM", Date("02/01/2006 15:04:05 PM", 1524799394))
Code:
func Date(format string, timestamp int64) string {
return time.Unix(timestamp, 0).Format(format)
}
This should ideally be fixed so tests can be run successfully in any timezone.
Although there are some ways to implement network transmission, but if implement super-global variables, it will greatly improve efficiency.
package main
import (
"fmt"
"strconv"
)
// Hex2bin hex2bin()
func Hex2bin(data string) (string, error) {
i, err := strconv.ParseInt(data, 16, 0)
if err != nil {
return "", err
}
return strconv.FormatInt(i, 2), nil
}
func main(){
fmt.Println(Hex2bin("48656c6c6f20576f726c6421"))
}
When I used this method, it returned an error below.
//strconv.ParseInt: parsing "48656c6c6f20576f726c6421": value out of range
If I use php function hex2bin()
:It shows us ,
Hello World!
pack()函数的实现
Report errors:undefined: syscall.Umask
编码后的字符串如果不带==,用go解密后的结果与php解密结果会有差异,建议判断一下如果没有==自动补齐后再解密就与php的一至了
The Strstr function is expected to return the entire haystack string when the haystack and needle parameters are identical. However, in the current implementation, it returns only the last character of the haystack string.
fmt.Println(Strstr("hello world", "hello world")) // hello world
fmt.Println(Strstr("hello world", "hello world")) // d
怎么不更新了呢 铁汁
这两个函数 有计划实现吗
// Empty empty()
func Empty(val interface{}) bool {
//if val == nil {
// return true
//}
//v := reflect.ValueOf(val)
//switch v.Kind() {
//case reflect.String, reflect.Array:
// return v.Len() == 0
//case reflect.Map, reflect.Slice:
// return v.Len() == 0 || v.IsNil()
//case reflect.Bool:
// return !v.Bool()
//case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
// return v.Int() == 0
//case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
// return v.Uint() == 0
//case reflect.Float32, reflect.Float64:
// return v.Float() == 0
//case reflect.Interface, reflect.Ptr:
// return v.IsNil()
//}
//
//return reflect.DeepEqual(val, reflect.Zero(v.Type()).Interface())
if val == nil {
return true
}
v := reflect.ValueOf(val)
switch v.Kind() {
case reflect.Map, reflect.Slice,reflect.Chan:
return v.Len() == 0 || v.IsNil()
default:
return v.IsZero()
}
}
详见pr : #6
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.