php2go

package module
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: MIT Imports: 31 Imported by: 0

README

PHP2Go

GoDoc Go Report Card MIT licensed

Use Golang to implement PHP's common built-in functions. About 140+ functions have been implemented.

Install

go get github.com/syyongx/php2go

Requirements

Go 1.10 or above.

PHP Functions

Date/Time Functions
time()
strtotime()
date()
checkdate()
sleep()
usleep()
String Functions
strpos()
stripos()
strrpos()
strripos()
str_replace()
ucfirst()
lcfirst()
ucwords()
substr()
strrev()
number_format()
chunk_split()
str_word_count()
wordwrap()
strlen()
str_repeat()
strstr()
strtr()
str_shuffle()
trim()
ltrim()
rtrim()
explode()
strtoupper()
strtolower()
chr()
ord()
nl2br()
json_encode()
json_decode()
addslashes()
stripslashes()
quotemeta()
htmlentities()
html_entity_decode()
md5()
md5_file()
sha1()
sha1_file()
crc32()
levenshtein()
similar_text()
soundex()
parse_str()
Multibyte String Functions
mb_strlen()
mb_strtoupper()
URL Functions
base64_encode()
base64_decode()
parse_url()
urlencode()
urldecode()
rawurlencode()
rawurldecode()
http_build_query()
Array(Slice/Map) Functions
array_fill()
array_flip()
array_keys()
array_values()
array_merge()
array_chunk()
array_pad()
array_slice()
array_rand()
array_column()
array_push()
array_pop()
array_unshift()
array_shift()
array_key_exists()
array_combine()
array_reverse()
implode()
in_array()
Mathematical Functions
abs()
rand()
round()
floor()
ceil()
pi()
max()
min()
decbin()
bindec()
hex2bin()
bin2hex()
dechex()
hexdec()
decoct()
Octdec()
base_convert()
is_nan()
CSPRNG Functions
random_bytes()
random_int()
Directory/Filesystem Functions
stat()
pathinfo()
file_exists()
is_file()
is_dir()
filesize()
file_put_contents()
file_get_contents()
unlink()
delete()
copy()
is_readable()
is_writeable()
rename()
touch()
mkdir()
getcwd()
realpath()
basename()
chmod()
chown()
fclose()
filemtime()
fgetcsv()
glob()
Variable handling Functions
empty()
is_numeric()
Program execution Functions
exec()
system()
passthru()
Network Functions
gethostname()
gethostbyname()
gethostbynamel()
gethostbyaddr()
ip2long()
long2ip()
Misc. Functions
echo()
uniqid()
exit()
die()
getenv()
putenv()
memory_get_usage()
memory_get_peak_usage()
version_compare()
zip_open()
Ternary(condition bool, trueVal, falseVal interface{}) interface{}

LICENSE

PHP2Go source code is licensed under the MIT Licence.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiskFreeSpace

func DiskFreeSpace(directory string) (uint64, error)

DiskFreeSpace disk_free_space()

func DiskTotalSpace

func DiskTotalSpace(directory string) (uint64, error)

DiskTotalSpace disk_total_space()

func Umask

func Umask(mask int) int

Umask umask()

Types

type PHP

type PHP struct{}

func (PHP) Abs

func (PHP) Abs(number float64) float64

Abs abs()

func (PHP) Addslashes

func (PHP) Addslashes(str string) string

Addslashes addslashes()

func (PHP) ArrayChunk

func (PHP) ArrayChunk(s []interface{}, size int) [][]interface{}

ArrayChunk array_chunk()

func (PHP) ArrayColumn

func (PHP) ArrayColumn(input map[string]map[string]interface{}, columnKey string) []interface{}

ArrayColumn array_column()

func (PHP) ArrayCombine

func (PHP) ArrayCombine(s1, s2 []interface{}) map[interface{}]interface{}

ArrayCombine array_combine()

func (PHP) ArrayFill

func (PHP) ArrayFill(startIndex int, num uint, value interface{}) map[int]interface{}

ArrayFill array_fill()

func (PHP) ArrayFlip

func (PHP) ArrayFlip(m map[interface{}]interface{}) map[interface{}]interface{}

ArrayFlip array_flip()

func (PHP) ArrayKeyExists

func (PHP) ArrayKeyExists(key interface{}, m map[interface{}]interface{}) bool

ArrayKeyExists array_key_exists()

func (PHP) ArrayKeys

func (PHP) ArrayKeys(elements map[interface{}]interface{}) []interface{}

ArrayKeys array_keys()

func (PHP) ArrayMerge

func (PHP) ArrayMerge(ss ...[]interface{}) []interface{}

ArrayMerge array_merge()

func (PHP) ArrayPad

func (PHP) ArrayPad(s []interface{}, size int, val interface{}) []interface{}

ArrayPad array_pad()

func (PHP) ArrayPop

func (PHP) ArrayPop(s *[]interface{}) interface{}

ArrayPop array_pop() Pop the element off the end of slice

func (PHP) ArrayPush

func (PHP) ArrayPush(s *[]interface{}, elements ...interface{}) int

ArrayPush array_push() Push one or more elements onto the end of slice

func (PHP) ArrayRand

func (PHP) ArrayRand(elements []interface{}) []interface{}

ArrayRand array_rand()

func (PHP) ArrayReverse

func (PHP) ArrayReverse(s []interface{}) []interface{}

ArrayReverse array_reverse()

func (PHP) ArrayShift

func (PHP) ArrayShift(s *[]interface{}) interface{}

ArrayShift array_shift() Shift an element off the beginning of slice

func (PHP) ArraySlice

func (PHP) ArraySlice(s []interface{}, offset, length uint) []interface{}

ArraySlice array_slice()

func (PHP) ArrayUnshift

func (PHP) ArrayUnshift(s *[]interface{}, elements ...interface{}) int

ArrayUnshift array_unshift() Prepend one or more elements to the beginning of a slice

func (PHP) ArrayValues

func (PHP) ArrayValues(elements map[interface{}]interface{}) []interface{}

ArrayValues array_values()

func (PHP) Base64Decode

func (PHP) Base64Decode(str string) (string, error)

Base64Decode base64_decode()

func (PHP) Base64Encode

func (PHP) Base64Encode(str string) string

Base64Encode base64_encode()

func (PHP) BaseConvert

func (PHP) BaseConvert(number string, frombase, tobase int) (string, error)

BaseConvert base_convert()

func (PHP) Basename

func (PHP) Basename(path string) string

Basename basename()

func (PHP) Bin2hex

func (PHP) Bin2hex(str string) (string, error)

Bin2hex bin2hex()

func (PHP) Bindec

func (PHP) Bindec(str string) (string, error)

Bindec bindec()

func (PHP) Ceil

func (PHP) Ceil(value float64) float64

Ceil ceil()

func (PHP) Checkdate

func (PHP) Checkdate(month, day, year int) bool

Checkdate checkdate() Validate a Gregorian date

func (PHP) Chmod

func (PHP) Chmod(filename string, mode os.FileMode) bool

Chmod chmod()

func (PHP) Chown

func (PHP) Chown(filename string, uid, gid int) bool

Chown chown()

func (PHP) Chr

func (PHP) Chr(ascii int) string

Chr chr()

func (PHP) ChunkSplit

func (PHP) ChunkSplit(body string, chunklen uint, end string) string

ChunkSplit chunk_split()

func (PHP) Copy

func (PHP) Copy(source, dest string) (bool, error)

Copy copy()

func (PHP) Crc32

func (PHP) Crc32(str string) uint32

Crc32 crc32()

func (PHP) Date

func (PHP) Date(format string, timestamp int64) string

Date date() Date("02/01/2006 15:04:05 PM", 1524799394) Note: the behavior is inconsistent with php's date function

func (PHP) Decbin

func (PHP) Decbin(number int64) string

Decbin decbin()

func (PHP) Dechex

func (PHP) Dechex(number int64) string

Dechex dechex()

func (PHP) Decoct

func (PHP) Decoct(number int64) string

Decoct decoct()

func (PHP) Delete

func (PHP) Delete(filename string) error

Delete delete()

func (PHP) Die

func (PHP) Die(status int)

Die die()

func (PHP) Echo

func (PHP) Echo(args ...interface{})

Echo echo

func (PHP) Empty

func (PHP) Empty(val interface{}) bool

Empty empty()

func (PHP) Exec

func (PHP) Exec(command string, output *[]string, returnVar *int) string

Exec exec() returnVar, 0: succ; 1: fail Return the last line from the result of the command. command format eg:

"ls -a"
"/bin/bash -c \"ls -a\""

func (PHP) Exit

func (PHP) Exit(status int)

Exit exit()

func (PHP) Explode

func (PHP) Explode(delimiter, str string) []string

Explode explode()

func (PHP) Fclose

func (PHP) Fclose(handle *os.File) error

Fclose fclose()

func (PHP) Fgetcsv

func (PHP) Fgetcsv(handle *os.File, length int, delimiter rune) ([][]string, error)

Fgetcsv fgetcsv()

func (PHP) FileExists

func (PHP) FileExists(filename string) bool

FileExists file_exists()

func (PHP) FileGetContents

func (PHP) FileGetContents(filename string) (string, error)

FileGetContents file_get_contents()

func (PHP) FilePutContents

func (PHP) FilePutContents(filename string, data string, mode os.FileMode) error

FilePutContents file_put_contents()

func (PHP) FileSize

func (PHP) FileSize(filename string) (int64, error)

FileSize filesize()

func (PHP) Filemtime

func (PHP) Filemtime(filename string) (int64, error)

Filemtime filemtime()

func (PHP) Floor

func (PHP) Floor(value float64) float64

Floor floor()

func (PHP) Getcwd

func (PHP) Getcwd() (string, error)

Getcwd getcwd()

func (PHP) Getenv

func (PHP) Getenv(varname string) string

Getenv getenv()

func (PHP) Gethostbyaddr

func (PHP) Gethostbyaddr(ipAddress string) (string, error)

Gethostbyaddr gethostbyaddr() Get the Internet host name corresponding to a given IP address

func (PHP) Gethostbyname

func (PHP) Gethostbyname(hostname string) (string, error)

Gethostbyname gethostbyname() Get the IPv4 address corresponding to a given Internet host name

func (PHP) Gethostbynamel

func (PHP) Gethostbynamel(hostname string) ([]string, error)

Gethostbynamel gethostbynamel() Get a list of IPv4 addresses corresponding to a given Internet host name

func (PHP) Gethostname

func (PHP) Gethostname() (string, error)

Gethostname gethostname()

func (PHP) Glob

func (PHP) Glob(pattern string) ([]string, error)

Glob glob()

func (PHP) HTMLEntityDecode

func (PHP) HTMLEntityDecode(str string) string

HTMLEntityDecode html_entity_decode()

func (PHP) HTTPBuildQuery

func (PHP) HTTPBuildQuery(queryData url.Values) string

HTTPBuildQuery http_build_query()

func (PHP) Hex2bin

func (PHP) Hex2bin(data string) (string, error)

Hex2bin hex2bin()

func (PHP) Hexdec

func (PHP) Hexdec(str string) (int64, error)

Hexdec hexdec()

func (PHP) Htmlentities

func (PHP) Htmlentities(str string) string

Htmlentities htmlentities()

func (PHP) IP2long

func (PHP) IP2long(ipAddress string) uint32

IP2long ip2long() IPv4

func (PHP) Implode

func (PHP) Implode(glue string, pieces []string) string

Implode implode()

func (PHP) InArray

func (PHP) InArray(needle interface{}, haystack interface{}) bool

InArray in_array() haystack supported types: slice, array or map

func (PHP) IsDir

func (PHP) IsDir(filename string) (bool, error)

IsDir is_dir()

func (PHP) IsFile

func (PHP) IsFile(filename string) bool

IsFile is_file()

func (PHP) IsNan

func (PHP) IsNan(val float64) bool

IsNan is_nan()

func (PHP) IsNumeric

func (PHP) IsNumeric(val interface{}) bool

IsNumeric is_numeric() Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. In PHP hexadecimal (e.g. 0xf4c3b00c) is not supported, but IsNumeric is supported.

func (PHP) IsReadable

func (PHP) IsReadable(filename string) bool

IsReadable is_readable()

func (PHP) IsWriteable

func (PHP) IsWriteable(filename string) bool

IsWriteable is_writeable()

func (PHP) JSONDecode

func (PHP) JSONDecode(data []byte, val interface{}) error

JSONDecode json_decode()

func (PHP) JSONEncode

func (PHP) JSONEncode(val interface{}) ([]byte, error)

JSONEncode json_encode()

func (PHP) Lcfirst

func (PHP) Lcfirst(str string) string

Lcfirst lcfirst()

func (PHP) Levenshtein

func (PHP) Levenshtein(str1, str2 string, costIns, costRep, costDel int) int

Levenshtein levenshtein() costIns: Defines the cost of insertion. costRep: Defines the cost of replacement. costDel: Defines the cost of deletion.

func (PHP) Long2ip

func (PHP) Long2ip(properAddress uint32) string

Long2ip long2ip() IPv4

func (PHP) Ltrim

func (PHP) Ltrim(str string, characterMask ...string) string

Ltrim ltrim()

func (PHP) Max

func (PHP) Max(nums ...float64) float64

Max max()

func (PHP) MbStrlen

func (PHP) MbStrlen(str string) int

MbStrlen mb_strlen()

func (PHP) MbStrtoupper

func (PHP) MbStrtoupper(str string) string

MbStrtoupper mb_strtoupper() Make a string uppercase

func (PHP) Md5

func (PHP) Md5(str string) string

Md5 md5()

func (PHP) Md5File

func (PHP) Md5File(path string) (string, error)

Md5File md5_file()

func (PHP) MemoryGetPeakUsage

func (PHP) MemoryGetPeakUsage(realUsage bool) uint64

MemoryGetPeakUsage memory_get_peak_usage() return in bytes

func (PHP) MemoryGetUsage

func (PHP) MemoryGetUsage(realUsage bool) uint64

MemoryGetUsage memory_get_usage() return in bytes

func (PHP) Min

func (PHP) Min(nums ...float64) float64

Min min()

func (PHP) Mkdir

func (PHP) Mkdir(filename string, mode os.FileMode) error

Mkdir mkdir()

func (PHP) Nl2br

func (PHP) Nl2br(str string, isXhtml bool) string

Nl2br nl2br() \n\r, \r\n, \r, \n

func (PHP) NumberFormat

func (PHP) NumberFormat(number float64, decimals uint, decPoint, thousandsSep string) string

NumberFormat number_format() decimals: Sets the number of decimal points. decPoint: Sets the separator for the decimal point. thousandsSep: Sets the thousands' separator.

func (PHP) Octdec

func (PHP) Octdec(str string) (int64, error)

Octdec Octdec()

func (PHP) Ord

func (PHP) Ord(char string) int

Ord ord()

func (PHP) Pack

func (PHP) Pack(order binary.ByteOrder, data interface{}) (string, error)

Pack pack()

func (PHP) ParseStr

func (PHP) ParseStr(encodedString string, result map[string]interface{}) error

ParseStr parse_str() f1=m&f2=n -> map[f1:m f2:n] f[a]=m&f[b]=n -> map[f:map[a:m b:n]] f[a][a]=m&f[a][b]=n -> map[f:map[a:map[a:m b:n]]] f[]=m&f[]=n -> map[f:[m n]] f[a][]=m&f[a][]=n -> map[f:map[a:[m n]]] f[][]=m&f[][]=n -> map[f:[map[]]] // Currently does not support nested slice. f=m&f[a]=n -> error // This is not the same as PHP. a .[[b=c -> map[a___[b:c]

func (PHP) ParseURL

func (PHP) ParseURL(str string, component int) (map[string]string, error)

ParseURL parse_url() Parse a URL and return its components -1: all; 1: scheme; 2: host; 4: port; 8: user; 16: pass; 32: path; 64: query; 128: fragment

func (PHP) Passthru

func (PHP) Passthru(command string, returnVar *int)

Passthru passthru() returnVar, 0: succ; 1: fail

func (PHP) Pathinfo

func (PHP) Pathinfo(path string, options int) map[string]string

Pathinfo pathinfo() -1: all; 1: dirname; 2: basename; 4: extension; 8: filename Usage: Pathinfo("/home/go/path/src/php2go/php2go.go", 1|2|4|8)

func (PHP) Pi

func (PHP) Pi() float64

Pi pi()

func (PHP) Putenv

func (PHP) Putenv(setting string) error

Putenv putenv() The setting, like "FOO=BAR"

func (PHP) Quotemeta

func (PHP) Quotemeta(str string) string

Quotemeta quotemeta()

func (PHP) Rand

func (PHP) Rand(min, max int) int

Rand rand() Range: [0, 2147483647]

func (PHP) RandomBytes

func (PHP) RandomBytes(length int) ([]byte, error)

RandomBytes random_bytes()

func (PHP) RandomInt

func (PHP) RandomInt(min, max int) (int, error)

RandomInt random_int()

func (PHP) Rawurldecode

func (PHP) Rawurldecode(str string) (string, error)

Rawurldecode rawurldecode()

func (PHP) Rawurlencode

func (PHP) Rawurlencode(str string) string

Rawurlencode rawurlencode()

func (PHP) Realpath

func (PHP) Realpath(path string) (string, error)

Realpath realpath()

func (PHP) Rename

func (PHP) Rename(oldname, newname string) error

Rename rename()

func (PHP) Round

func (PHP) Round(value float64, precision int) float64

Round round()

func (PHP) Rtrim

func (PHP) Rtrim(str string, characterMask ...string) string

Rtrim rtrim()

func (PHP) Sha1

func (PHP) Sha1(str string) string

Sha1 sha1()

func (PHP) Sha1File

func (PHP) Sha1File(path string) (string, error)

Sha1File sha1_file()

func (PHP) SimilarText

func (PHP) SimilarText(first, second string, percent *float64) int

SimilarText similar_text()

func (PHP) Sleep

func (PHP) Sleep(t int64)

Sleep sleep()

func (PHP) Soundex

func (PHP) Soundex(str string) string

Soundex soundex() Calculate the soundex key of a string.

func (PHP) Stat

func (PHP) Stat(filename string) (os.FileInfo, error)

Stat stat()

func (PHP) StrRepeat

func (PHP) StrRepeat(input string, multiplier int) string

StrRepeat str_repeat()

func (PHP) StrReplace

func (PHP) StrReplace(search, replace, subject string, count int) string

StrReplace str_replace()

func (PHP) StrShuffle

func (PHP) StrShuffle(str string) string

StrShuffle str_shuffle()

func (PHP) StrWordCount

func (PHP) StrWordCount(str string) []string

StrWordCount str_word_count()

func (PHP) Stripos

func (PHP) Stripos(haystack, needle string, offset int) int

Stripos stripos()

func (PHP) Stripslashes

func (PHP) Stripslashes(str string) string

Stripslashes stripslashes()

func (PHP) Strlen

func (PHP) Strlen(str string) int

Strlen strlen()

func (PHP) Strpos

func (PHP) Strpos(haystack, needle string, offset int) int

Strpos strpos()

func (PHP) Strrev

func (PHP) Strrev(str string) string

Strrev strrev()

func (PHP) Strripos

func (PHP) Strripos(haystack, needle string, offset int) int

Strripos strripos()

func (PHP) Strrpos

func (PHP) Strrpos(haystack, needle string, offset int) int

Strrpos strrpos()

func (PHP) Strstr

func (PHP) Strstr(haystack string, needle string) string

Strstr strstr()

func (PHP) Strtolower

func (PHP) Strtolower(str string) string

Strtolower strtolower()

func (PHP) Strtotime

func (PHP) Strtotime(format, strtime string) (int64, error)

Strtotime strtotime() Strtotime("02/01/2006 15:04:05", "02/01/2016 15:04:05") == 1451747045 Strtotime("3 04 PM", "8 41 PM") == -62167144740

func (PHP) Strtoupper

func (PHP) Strtoupper(str string) string

Strtoupper strtoupper()

func (PHP) Strtr

func (PHP) Strtr(haystack string, params ...interface{}) string

Strtr strtr()

If the parameter length is 1, type is: map[string]string Strtr("baab", map[string]string{"ab": "01"}) will return "ba01" If the parameter length is 2, type is: string, string Strtr("baab", "ab", "01") will return "1001", a => 0; b => 1.

func (PHP) Substr

func (PHP) Substr(str string, start uint, length int) string

Substr substr()

func (PHP) System

func (PHP) System(command string, returnVar *int) string

System system() returnVar, 0: succ; 1: fail Returns the last line of the command output on success, and "" on failure.

func (PHP) Ternary

func (PHP) Ternary(condition bool, trueVal, falseVal interface{}) interface{}

Ternary Ternary expression max := Ternary(a > b, a, b).(int)

func (PHP) Time

func (PHP) Time() int64

Time time()

func (PHP) Touch

func (PHP) Touch(filename string) (bool, error)

Touch touch()

func (PHP) Trim

func (PHP) Trim(str string, characterMask ...string) string

Trim trim()

func (PHP) URLDecode

func (PHP) URLDecode(str string) (string, error)

URLDecode urldecode()

func (PHP) URLEncode

func (PHP) URLEncode(str string) string

URLEncode urlencode()

func (PHP) Ucfirst

func (PHP) Ucfirst(str string) string

Ucfirst ucfirst()

func (PHP) Ucwords

func (PHP) Ucwords(str string) string

Ucwords ucwords()

func (PHP) Uniqid

func (PHP) Uniqid(prefix string) string

Uniqid uniqid()

func (PHP) Unlink(filename string) error

Unlink unlink()

func (PHP) Unpack

func (PHP) Unpack(order binary.ByteOrder, data string) (interface{}, error)

Unpack unpack()

func (PHP) Usleep

func (PHP) Usleep(t int64)

Usleep usleep()

func (PHP) VersionCompare

func (PHP) VersionCompare(version1, version2, operator string) bool

VersionCompare version_compare() The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively. special version strings these are handled in the following order, (any string not found) < dev < alpha = a < beta = b < RC = rc < # < pl = p Usage: VersionCompare("1.2.3-alpha", "1.2.3RC7", '>=') VersionCompare("1.2.3-beta", "1.2.3pl", 'lt') VersionCompare("1.1_dev", "1.2any", 'eq')

func (PHP) Wordwrap

func (PHP) Wordwrap(str string, width uint, br string, cut bool) string

Wordwrap wordwrap()

func (PHP) ZipOpen

func (PHP) ZipOpen(filename string) (*zip.ReadCloser, error)

ZipOpen zip_open()

Jump to

Keyboard shortcuts

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