php2go

package module
v0.0.0-...-443919c Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 30 Imported by: 0

README

php2go

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

Install

go get github.com/syyongx/php2go

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()
mb_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()
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()
Mathematical Functions
abs()
rand()
round()
floor()
ceil()
pi()
max()
min()
decbin()
bindec()
hex2bin()
bin2hex()
dechex()
hexdec()
decoct()
Octdec()
base_convert()
is_nan()
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()
disk_free_space()
disk_total_space()
glob()
umask()
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()
version_compare()
zip_open()
Ternary(condition bool, trueVal, falseVal interface{}) interface{}

LICENSE

php2go source code is licensed under the MIT Licence.

Documentation

Overview

php2go functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(number float64) float64

abs()

func Addslashes

func Addslashes(str string) string

addslashes()

func ArrayChunk

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

array_chunk()

func ArrayColumn

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

array_column()

func ArrayCombine

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

array_combine()

func ArrayFill

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

array_fill()

func ArrayFlip

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

array_flip()

func ArrayKeyExists

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

array_key_exists()

func ArrayKeys

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

array_keys()

func ArrayMerge

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

array_merge()

func ArrayPad

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

array_pad()

func ArrayPop

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

array_pop() Pop the element off the end of slice

func ArrayPush

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

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

func ArrayRand

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

array_rand()

func ArrayReverse

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

array_reverse()

func ArrayShift

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

array_shift() Shift an element off the beginning of slice

func ArraySlice

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

array_slice()

func ArrayUnshift

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

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

func ArrayValues

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

array_values()

func Base64Decode

func Base64Decode(str string) (string, error)

base64_decode()

func Base64Encode

func Base64Encode(str string) string

base64_encode()

func BaseConvert

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

base_convert()

func Basename

func Basename(path string) string

basename()

func Bin2hex

func Bin2hex(str string) (string, error)

bin2hex()

func Bindec

func Bindec(str string) (string, error)

bindec()

func Ceil

func Ceil(value float64) float64

ceil()

func Checkdate

func Checkdate(month, day, year int) bool

checkdate() Validate a Gregorian date

func Chmod

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

chmod()

func Chown

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

chown()

func Chr

func Chr(ascii int) string

chr()

func ChunkSplit

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

chunk_split()

func Copy

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

copy()

func Crc32

func Crc32(str string) uint32

crc32()

func Date

func Date(format string, timestamp int64) string

date() Date("02/01/2006 15:04:05 PM", 1524799394)

func Decbin

func Decbin(number int64) string

decbin()

func Dechex

func Dechex(number int64) string

dechex()

func Decoct

func Decoct(number int64) string

decoct()

func Delete

func Delete(filename string) error

delete()

func Die

func Die(status int)

die()

func Echo

func Echo(args ...interface{})

echo

func Empty

func Empty(val interface{}) bool

empty()

func Exec

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

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

func Exit

func Exit(status int)

exit()

func Explode

func Explode(delimiter, str string) []string

explode()

func Fclose

func Fclose(handle *os.File) error

fclose()

func Fgetcsv

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

fgetcsv()

func FileExists

func FileExists(filename string) bool

file_exists()

func FileGetContents

func FileGetContents(filename string) (string, error)

file_get_contents()

func FilePutContents

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

file_put_contents()

func FileSize

func FileSize(filename string) (int64, error)

filesize()

func Filemtime

func Filemtime(filename string) (int64, error)

filemtime()

func Floor

func Floor(value float64) float64

floor()

func Getcwd

func Getcwd() (string, error)

getcwd()

func Getenv

func Getenv(varname string) string

getenv()

func Gethostbyaddr

func Gethostbyaddr(ipAddress string) (string, error)

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

func Gethostbyname

func Gethostbyname(hostname string) (string, error)

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

func Gethostbynamel

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

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

func Gethostname

func Gethostname() (string, error)

gethostname()

func Glob

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

glob()

func Hex2bin

func Hex2bin(data string) (string, error)

hex2bin()

func Hexdec

func Hexdec(str string) (int64, error)

hexdec()

func HtmlEntityDecode

func HtmlEntityDecode(str string) string

html_entity_decode()

func Htmlentities

func Htmlentities(str string) string

htmlentities()

func HttpBuildQuery

func HttpBuildQuery(queryData url.Values) string

http_build_query()

func Implode

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

implode()

func Ip2long

func Ip2long(ipAddress string) uint32

ip2long() IPv4

func IsDir

func IsDir(filename string) (bool, error)

is_dir()

func IsFile

func IsFile(filename string) bool

is_file()

func IsNan

func IsNan(val float64) bool

is_nan()

func IsNumeric

func IsNumeric(val interface{}) bool

is_numeric()

func IsReadable

func IsReadable(filename string) bool

is_readable()

func IsWriteable

func IsWriteable(filename string) bool

is_writeable()

func JsonDecode

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

json_decode()

func JsonEncode

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

json_encode()

func Lcfirst

func Lcfirst(str string) string

lcfirst()

func Levenshtein

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

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

func Long2ip

func Long2ip(properAddress uint32) string

long2ip() IPv4

func Ltrim

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

ltrim()

func Max

func Max(nums ...float64) float64

max()

func MbStrlen

func MbStrlen(str string) int

mb_strlen()

func Md5

func Md5(str string) string

md5()

func Md5File

func Md5File(path string) (string, error)

md5_file()

func MemoryGetUsage

func MemoryGetUsage(realUsage bool) uint64

memory_get_usage() return in bytes

func Min

func Min(nums ...float64) float64

min()

func Mkdir

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

mkdir()

func Nl2br

func Nl2br(str string, isXhtml bool) string

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

func NumberFormat

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

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

func Octdec

func Octdec(str string) (int64, error)

Octdec()

func Ord

func Ord(char string) int

ord()

func Pack

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

pack()

func ParseStr

func ParseStr(encodedString string) (map[string][]string, error)

parse_str() Golang url.ParseQuery not same as PHP parse_str when processing array parameter.

func ParseUrl

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

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 Passthru

func Passthru(command string, returnVar *int)

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

func Pathinfo

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

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 Pi

func Pi() float64

pi()

func Putenv

func Putenv(setting string) error

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

func Quotemeta

func Quotemeta(str string) string

quotemeta()

func Rand

func Rand(min, max int) int

rand()

func Rawurldecode

func Rawurldecode(str string) (string, error)

rawurldecode()

func Rawurlencode

func Rawurlencode(str string) string

rawurlencode()

func Realpath

func Realpath(path string) (string, error)

realpath()

func Rename

func Rename(oldname, newname string) error

rename()

func Round

func Round(value float64) float64

round()

func Rtrim

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

rtrim()

func Sha1

func Sha1(str string) string

sha1()

func Sha1File

func Sha1File(path string) (string, error)

sha1_file()

func SimilarText

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

similar_text()

func Sleep

func Sleep(t int64)

sleep()

func Soundex

func Soundex(str string) string

soundex() Calculate the soundex key of a string.

func Stat

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

stat()

func StrRepeat

func StrRepeat(input string, multiplier int) string

str_repeat()

func StrReplace

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

str_replace()

func StrShuffle

func StrShuffle(str string) string

str_shuffle()

func StrWordCount

func StrWordCount(str string) []string

str_word_count()

func Stripos

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

stripos()

func Stripslashes

func Stripslashes(str string) string

stripslashes()

func Strlen

func Strlen(str string) int

strlen()

func Strpos

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

strpos()

func Strrev

func Strrev(str string) string

strrev()

func Strripos

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

strripos()

func Strrpos

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

strrpos()

func Strstr

func Strstr(haystack string, needle string) string

strstr()

func Strtolower

func Strtolower(str string) string

strtolower()

func Strtotime

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

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

func Strtoupper

func Strtoupper(str string) string

strtoupper()

func Strtr

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

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 Substr

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

substr()

func System

func System(command string, returnVar *int) string

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

func Ternary

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

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

func Time

func Time() int64

time()

func Touch

func Touch(filename string) (bool, error)

touch()

func Trim

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

trim()

func Ucfirst

func Ucfirst(str string) string

ucfirst()

func Ucwords

func Ucwords(str string) string

ucwords()

func Uniqid

func Uniqid(prefix string) string

uniqid()

func Unlink(filename string) error

unlink()

func Unpack

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

unpack()

func UrlDecode

func UrlDecode(str string) (string, error)

urldecode()

func UrlEncode

func UrlEncode(str string) string

urlencode()

func Usleep

func Usleep(t int64)

usleep()

func VersionCompare

func VersionCompare(version1, version2, operator string) bool

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 Wordwrap

func Wordwrap(str string, width uint, br string) string

wordwrap()

func ZipOpen

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

zip_open()

Types

This section is empty.

Jump to

Keyboard shortcuts

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