helpers

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: MIT Imports: 33 Imported by: 4

README

HELPERS

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/xiya-team/helpers

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()
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()
in_array()
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()
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()
version_compare()
zip_open()
Ternary(condition bool, trueVal, falseVal interface{}) interface{}

LICENSE

HELPERS source code is licensed under the MIT Licence.

Documentation

Overview

PHP built-in function library with Go language

Index

Constants

View Source
const (
	StrPadRight = "STR_PAD_RIGHT"
	StrPadLeft  = "STR_PAD_LEFT"
)

Constants for StrPad

Variables

View Source
var (
	FORMAT_DATE     string = "2006-01-02"
	FORMAT_DATETIME string = "2006-01-02 15:04:05"
	CASE_UPPER      int    = 1 //转为大写
	CASE_LOWER      int    = 0 //转为小写
	RET_STRING             = 0 //结果为STRING
	RET_INT                = 1 //结果为INT
	RET_INT64              = 2 //结果为INT64
)

Functions

func Abs

func Abs(number float64) float64

Abs abs()

func Acos

func Acos(x complex128) complex128

Acos - Arc cosine

func Acosh

func Acosh(x complex128) complex128

Acosh - Inverse hyperbolic cosine

func Addcslashes

func Addcslashes(s string, c byte) string

Addcslashes - Quote string with slashes in a C style

func Addslashes

func Addslashes(str string) string

Addslashes addslashes()

func Array

func Array(v ...interface{}) []interface{}

Array - Create an array

func ArrayChangeKeyase added in v1.0.3

func ArrayChangeKeyase(arrayOrigin map[string]interface{}, changeTo int) map[string]interface{}

func ArrayChunk

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

ArrayChunk array_chunk()

func ArrayColumn

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

ArrayColumn array_column() ArrayColumn — Return the values from a single column in the input array

func ArrayColumnMapStringStringRetArrayString added in v1.0.3

func ArrayColumnMapStringStringRetArrayString(array []map[string]string, column string) []string

func ArrayColumnRetArrayString added in v1.0.3

func ArrayColumnRetArrayString(array []map[string]interface{}, column string) []string

func ArrayCombine

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

ArrayCombine array_combine()

func ArrayCountValues

func ArrayCountValues(s []interface{}) map[interface{}]uint

ArrayCountValues — Counts all the values of an array

func ArrayDiff added in v1.0.3

func ArrayDiff(array1, array2 []interface{}) []interface{}

func ArrayFill

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

ArrayFill array_fill()

func ArrayFillKeys

func ArrayFillKeys(keys []interface{}, value interface{}) map[interface{}]interface{}

ArrayFillKeys - Fill an array with values, specifying keys

func ArrayFlip

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

ArrayFlip - Exchanges all keys with their associated values in an array

func ArrayIntersect

func ArrayIntersect(nums1, nums2 []int) []int

ArrayIntersect — Computes the intersection of arrays

func ArrayKeyExists

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

ArrayKeyExists array_key_exists()

func ArrayKeyExistsString added in v1.0.3

func ArrayKeyExistsString(needle string, haystack map[string]interface{}) bool

func ArrayKeyFirst added in v1.0.3

func ArrayKeyFirst(array map[interface{}]interface{}) interface{}

*

  • array_key_first — Gets the first key of an array
  • @params map[interface{}]interface{} array An array. *
  • @return interface{}

func ArrayKeyLast added in v1.0.3

func ArrayKeyLast(arr map[interface{}]interface{}) interface{}

*

  • array_key_first — Gets the first key of an array
  • @params map[interface{}]interface{} array An array. *
  • @return interface{}

func ArrayKeys

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

ArrayKeys array_keys()

func ArrayKeysInt added in v1.0.3

func ArrayKeysInt(array map[int]interface{}) []int

key的类型为int

func ArrayKeysInterface added in v1.0.3

func ArrayKeysInterface(array map[interface{}]interface{}) []interface{}

key的类型为interface{}

func ArrayMerge

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

ArrayMerge array_merge()

func ArrayMergeString added in v1.0.3

func ArrayMergeString(arr1, arr2 []string) []string

对于切片不建议使用本方法,而要直接使用 append

func ArrayPad

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

ArrayPad array_pad()

func ArrayPop

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

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

func ArrayPush

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

ArrayPush - Push one or more elements onto the end of array

func ArrayRand

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

ArrayRand array_rand()

func ArrayReverse

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

ArrayReverse array_reverse()

func ArraySearch added in v1.0.3

func ArraySearch(needle interface{}, haystack []interface{}) int

func ArraySearchString added in v1.0.3

func ArraySearchString(needle string, haystack []string) int

func ArrayShift

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

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

func ArraySlice

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

ArraySlice array_slice()

func ArrayUnshift

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

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

func ArrayValues

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

ArrayValues array_values()

func Asin

func Asin(x complex128) complex128

Asin - Arc sine

func Asinh

func Asinh(x complex128) complex128

Asinh - Inverse hyperbolic sine

func Atan

func Atan(x complex128) complex128

Atan - Arc tangent

func Atan2

func Atan2(y, x float64) float64

Atan2 - Arc tangent of two variables

func Atanh

func Atanh(x complex128) complex128

Atanh - Inverse hyperbolic tangent

func Base64Decode

func Base64Decode(s string) (string, error)

Base64Decode - Decodes data encoded with MIME base64

func Base64Encode

func Base64Encode(s string) string

Base64Encode - Encodes data with MIME base64

func BaseConvert

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

BaseConvert - Convert a number between arbitrary bases

func Basename

func Basename(path string) string

Basename - Returns trailing name component of path

func Bin2hex

func Bin2hex(str string) (string, error)

Bin2hex bin2hex()

func Bindec

func Bindec(str string) (string, error)

Bindec bindec()

func Boolval

func Boolval(val interface{}) bool

Boolval - Get the boolean value of a variable

func CamelStringToUnderline added in v1.0.3

func CamelStringToUnderline(s string) string

*

驼峰字符串转成下划线+小些字母
例如: 	abcdAccc ==> abcd_accc
		AbcdA    ==> abcd_a
如果遇到有大写字母的地方,则将在前一位将加上下划线 "_", 将大写字母转成小字母(如果是首字母,则只是转成小谢即可)

func Ceil

func Ceil(x float64) float64

Ceil - Round fractions up

func Chdir

func Chdir(dir string) error

Chdir - Change directory

func Checkdate

func Checkdate(month, day, year uint) bool

Checkdate - Validate a Gregorian date

func Chgrp

func Chgrp(name string, uid, gid int) error

Chgrp - Changes file group

func Chmod

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

Chmod chmod()

func Chown

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

Chown chown()

func Chr

func Chr(ascii int) string

Chr - Return a specific character

func ChunkSplit

func ChunkSplit(str string, chunkLen int, end string) string

ChunkSplit - Split a string into smaller chunks

func Closedir

func Closedir(fd int) (err error)

Closedir - Close directory's handle

func Copy

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

Copy copy()

func Cos

func Cos(x float64) float64

Cos - Cosine

func Cosh

func Cosh(x float64) float64

Cosh - Hyperbolic cosine

func Count

func Count(v []interface{}) int

Count - Count all elements in an array, or something in an object

func Crc32

func Crc32(str string) uint32

Crc32 crc32()

func Date

func Date(timestamp int64) string

dateTimeFormat 格式如:"2006-01-02 15:04:05"

func DateAdd

func DateAdd(t time.Time, years int, months int, days int) time.Time

DateAdd - Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object

func DateAfter added in v1.0.3

func DateAfter(seconds int64, timestamp int64) string

多少秒后

func DateBefore added in v1.0.3

func DateBefore(seconds int64, timestamp int64) string

多少秒前

func DateDaysafter added in v1.0.3

func DateDaysafter(days int64, timestamp int64) string

多少天后

func DateDaysbefore added in v1.0.3

func DateDaysbefore(days int64, timestamp int64) string

多少天前

func DateHoursafter added in v1.0.3

func DateHoursafter(hours int64, timestamp int64) string

多少小时后

func DateHoursbefore added in v1.0.3

func DateHoursbefore(hours int64, timestamp int64) string

多少小时前

func DateMinutesbefore added in v1.0.3

func DateMinutesbefore(minutes int64, timestamp int64) string

多少分钟前

func DateNow added in v1.0.3

func DateNow() string

当前日期

func DateToday added in v1.0.3

func DateToday() string

当前日期

func DateTomorrow added in v1.0.3

func DateTomorrow() string

明天日期

func Date_minutesafter added in v1.0.3

func Date_minutesafter(minutes int64, timestamp int64) string

多少分钟后

func Datetime added in v1.0.3

func Datetime(timestamp int64) string

dateTimeFormat 格式如:"2006-01-02 15:04:05"

func DatetimeAfter added in v1.0.3

func DatetimeAfter(seconds int64, timestamp int64) string

多少秒后

func DatetimeBefore added in v1.0.3

func DatetimeBefore(seconds int64, timestamp int64) string

多少秒前

func DatetimeDaysafter added in v1.0.3

func DatetimeDaysafter(days int64, timestamp int64) string

多少天后

func DatetimeDaysbefore added in v1.0.3

func DatetimeDaysbefore(days int64, timestamp int64) string

多少天前

func DatetimeHoursafter added in v1.0.3

func DatetimeHoursafter(hours int64, timestamp int64) string

多少小时后

func DatetimeHoursbefore added in v1.0.3

func DatetimeHoursbefore(hours int64, timestamp int64) string

多少小时前

func DatetimeMinutesafter added in v1.0.3

func DatetimeMinutesafter(minutes int64, timestamp int64) string

多少分钟后

func DatetimeMinutesbefore added in v1.0.3

func DatetimeMinutesbefore(minutes int64, timestamp int64) string

多少分钟前

func DatetimeNow added in v1.0.3

func DatetimeNow() string

当前日期时间

func DatetimeToday added in v1.0.3

func DatetimeToday() string

当前日期时间

func DatetimeTomorrow added in v1.0.3

func DatetimeTomorrow() string

明天时间

func Decbin

func Decbin(x int64) string

Decbin - Decimal to binary

func Dechex

func Dechex(x int64) string

Dechex - Decimal to hexadecimal

func Decoct

func Decoct(x int64) string

Decoct - Decimal to octal

func Delete

func Delete(filename string) error

Delete delete()

func Die

func Die(status int)

Die die()

func Dirname

func Dirname(dirPth string) ([]os.FileInfo, error)

Dirname - Returns a parent directory's path

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 Echo

func Echo(args ...interface{})

Echo - Output one or more strings

func Empty

func Empty(v interface{}) bool

Empty - Determine whether a variable is empty

func Exec

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

Exec - Execute an external program

func Exit

func Exit(status int)

Exit exit()

func Exp

func Exp(x float64) float64

Exp - Calculates the exponent of e

func Explode

func Explode(delimiter, str string) []string

Explode explode()

func Expm1

func Expm1(x float64) float64

Expm1 - Returns exp(number) - 1 computed in a way that is accurate even when the value of number is close to zero

func Fclose

func Fclose(handle *os.File) error

Fclose fclose()

func Fgetcsv

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

Fgetcsv fgetcsv()

func FileExists

func FileExists(filename string) bool

FileExists file_exists()

func FileExits added in v1.0.3

func FileExits(path string) bool

func FileExitsDetail added in v1.0.3

func FileExitsDetail(path string) (bool, error)

func FileGetContents

func FileGetContents(filename string) (string, error)

FileGetContents file_get_contents()

func FilePutContents

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

FilePutContents file_put_contents()

func FileSize

func FileSize(filename string) (int64, error)

FileSize filesize()

func Filemtime

func Filemtime(filename string) (int64, error)

Filemtime filemtime() 获取文件修改时间 返回unix时间戳

func Floor

func Floor(x float64) float64

Floor - Round fractions down

func GetENV added in v1.0.7

func GetENV() (env string)

* 获取当前环境

func GetHtmlTranslationTable

func GetHtmlTranslationTable() map[string]string

GetHtmlTranslationTable - Returns the translation table used by htmlspecialchars() and htmlentities()

func GetIpInfo added in v1.0.6

func GetIpInfo(ip string) string

func Getcwd

func Getcwd() (string, error)

Getcwd getcwd()

func Getenv

func Getenv(varname string) string

Getenv getenv()

func Gethostbyaddr

func Gethostbyaddr(ipAddress string) (string, error)

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

func Gethostbyname

func Gethostbyname(hostname string) (string, error)

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

func Gethostbynamel

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

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

func Gethostname

func Gethostname() (string, error)

Gethostname gethostname()

func Gettype

func Gettype(v interface{}) string

Gettype - Get the type of a variable

func Glob

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

Glob - Find pathnames matching a pattern

func HTMLEntityDecode

func HTMLEntityDecode(str string) string

HTMLEntityDecode html_entity_decode()

func HTTPBuildQuery

func HTTPBuildQuery(queryData url.Values) string

HTTPBuildQuery http_build_query()

func Hex2bin

func Hex2bin(data string) (string, error)

Hex2bin hex2bin()

func Hexdec

func Hexdec(str string) (int64, error)

Hexdec hexdec()

func HtmlEntityDecode added in v1.0.3

func HtmlEntityDecode(str string) string

func Htmlentities

func Htmlentities(str string) string

将字符转换为 HTML 转义字符

func Htmlspecialchars

func Htmlspecialchars(s string) string

Htmlspecialchars - Convert special characters to HTML entities

func HtmlspecialcharsDecode

func HtmlspecialcharsDecode(s string) string

HtmlspecialcharsDecode - Convert special HTML entities back to characters

func IP2long

func IP2long(ipAddress string) uint32

IP2long ip2long() IPv4

func Implode

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

Implode implode()

func InArray

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

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

func Intval

func Intval(str string) (int, error)

Intval - Get the integer value of a variable

func IsBool

func IsBool(v interface{}) bool

IsBool - Finds out whether a variable is a boolean

func IsDir

func IsDir(filename string) (bool, error)

IsDir is_dir()

func IsFile

func IsFile(filename string) bool

IsFile is_file()

func IsFinite

func IsFinite(f float64, sign int) bool

IsFinite - Finds whether a value is a legal finite number

func IsInfinite

func IsInfinite(f float64, sign int) bool

IsInfinite - Finds whether a value is infinite

func IsNan

func IsNan(f float64) bool

IsNan - Finds whether a value is not a number

func IsNumeric

func IsNumeric(x interface{}) (result bool)

IsNumeric - Finds whether a variable is a number or a numeric string

func IsReadable

func IsReadable(filename string) bool

IsReadable is_readable()

func IsWritable

func IsWritable(name string) bool

IsWritable - Tells whether the filename is writable

func IsWriteable

func IsWriteable(filename string) bool

IsWriteable is_writeable()

func JSONDecode

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

JSONDecode json_decode()

func JSONEncode

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

JSONEncode json_encode()

func Join

func Join(a []string, sep string) string

Join - Alias of implode()

func JsonDecode

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

JsonDecode - Decodes a JSON string

func JsonEncode

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

JsonEncode - Returns the JSON representation of a value

func Lcfirst

func Lcfirst(str string) string

Lcfirst lcfirst()

func Levenshtein

func 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 Log

func Log(x float64) float64

Log - Natural logarithm

func Log10

func Log10(x float64) float64

Log10 - Base-10 logarithm

func Log1p

func Log1p(x float64) float64

Log1p - Returns log(1 + number) computed in a way that is accurate even when the value of number is close to zero

func Long2ip

func Long2ip(properAddress uint32) string

Long2ip long2ip() IPv4

func Ltrim

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

Ltrim ltrim()

func MapCamelStringToUnderline added in v1.0.3

func MapCamelStringToUnderline(body map[string]interface{}) map[string]interface{}

*

将map下的所有键  由驼峰转成下划线

func MapMerge added in v1.0.3

func MapMerge(arr1, arr2 map[string]interface{}) map[string]interface{}

func MapMergeKeyInterface added in v1.0.3

func MapMergeKeyInterface(arr1, arr2 map[interface{}]interface{}) map[interface{}]interface{}

func MapMergeString added in v1.0.3

func MapMergeString(arr1, arr2 map[string]string) map[string]string

func MapUnderlineStringToCamel added in v1.0.3

func MapUnderlineStringToCamel(body map[string]interface{}) map[string]interface{}

*

将map下的所有键  由下划线转成驼峰

func Max

func Max(nums ...float64) float64

Max max()

func MbStrlen

func MbStrlen(s string) int

MbStrlen - Get string length

func MbSubstr

func MbSubstr(s string, start int, length ...int) string

MbSubstr - Get part of string

func Md5

func Md5(s string) string

Md5 - Calculate the md5 hash of a string

func Md5File

func Md5File(path string) (string, error)

Md5File md5_file()

func MemoryGetUsage

func MemoryGetUsage(realUsage bool) uint64

MemoryGetUsage memory_get_usage() return in bytes

func Min

func Min(nums ...float64) float64

Min min()

func Mkdir

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

Mkdir - Makes directory Mkdir mkdir()

func MkdirAll

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

func Nl2br

func Nl2br(str string, isXhtml bool) string

Nl2br - Inserts HTML line breaks before all newlines in a string

func NumberFormat

func 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 Octdec

func Octdec(str string) (int64, error)

Octdec Octdec()

func Ord

func Ord(char string) int

Ord ord()

func Pack

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

Pack pack()

func ParseStr

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

func ParseURL

func 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 ParseUrl

func ParseUrl(rawurl string) (*url.URL, error)

ParseUrl - Parse a URL and return its components

func Passthru

func Passthru(command string, returnVar *int)

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

func Pathinfo

func 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 Pi

func Pi() float64

Pi - Get value of pi

func Pow

func Pow(x, y float64) float64

Pow - Exponential expression

func Print

func Print(v interface{})

Print - Output a string

func PrintR

func PrintR(v interface{})

PrintR - Prints human-readable information about a variable

func Putenv

func Putenv(setting string) error

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

func Quotemeta

func Quotemeta(str string) string

Quotemeta quotemeta()

func Rand

func Rand(min, max int) int

Rand rand() Range: [0, 2147483647]

func Rawurldecode

func Rawurldecode(s string) (string, error)

Rawurldecode - Decodes URL-encoded string

func Rawurlencode

func Rawurlencode(s string) string

Rawurlencode - URL-encode according to RFC 3986

func Realpath

func Realpath(path string) (string, error)

Realpath - Returns canonicalized absolute pathname

func Rename

func Rename(oldpath, newpath string) error

Rename - Renames a file or directory

func Rmdir

func Rmdir(path string) error

Rmdir — Removes directory

func Round

func Round(x float64) float64

Round - Rounds a float

func Rtrim

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

Rtrim rtrim()

func Scandir

func Scandir(dirname string) ([]os.FileInfo, error)

scandir — List files and directories inside the specified path

func Sha1

func Sha1(s string) string

Sha1 - Calculate the sha1 hash of a string

func Sha1File

func Sha1File(path string) (string, error)

Sha1File sha1_file()

func SimilarText

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

SimilarText similar_text()

func Sin

func Sin(x float64) float64

Sin - Sine

func Sinh

func Sinh(x float64) float64

Sinh - Hyperbolic sine

func Sleep

func Sleep(s int64)

Sleep - Delay execution

func Soundex

func Soundex(str string) string

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

func Sqrt

func Sqrt(x float64) float64

Sqrt - Square root

func Stat

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

Stat - Gives information about a file

func StrPad

func StrPad(s string, length int, args ...string) string

StrPad - Pad a string to a certain length with another string

func StrRepeat

func StrRepeat(s string, count int) string

StrRepeat - Repeat a string

func StrReplace

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

StrReplace str_replace()

func StrShuffle

func StrShuffle(str string) string

StrShuffle str_shuffle()

func StrToTime added in v1.0.3

func StrToTime(strtime interface{}) int64

例如:2019-01-31 00:00:00

func StrToTimeDate added in v1.0.3

func StrToTimeDate(strtime interface{}) int64

例如:2019-01-31

func StrToTimeDateTime added in v1.0.3

func StrToTimeDateTime(strtime interface{}) int64

例如:2019-01-31 00:00:00

func StrWordCount

func StrWordCount(str string) []string

StrWordCount str_word_count()

func Stringval added in v1.0.3

func Stringval(value interface{}) string

func StripTags

func StripTags(s string) string

StripTags - Strip HTML and PHP tags from a string

func Stripos

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

Stripos stripos()

func Stripslashes

func Stripslashes(str string) string

Stripslashes stripslashes()

func Strlen

func Strlen(s string) int

Strlen - Get string length

func Strpos

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

Strpos strpos()

func Strrchr

func Strrchr(s, substr string) string

Strrchr - Find the last occurrence of a character in a string

func Strrev

func Strrev(str string) string

Strrev strrev()

func Strripos

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

Strripos strripos()

func Strrpos

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

Strrpos strrpos()

func Strstr

func Strstr(haystack string, needle string) string

Strstr strstr()

func Strtolower

func Strtolower(str string) string

Strtolower strtolower()

func Strtotime

func 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 Strtoupper

func Strtoupper(str string) string

Strtoupper strtoupper()

func Strtr

func 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 Strval

func Strval(val interface{}) string

Strval - Get string value of a variable

func Substr

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

Substr substr()

func SubstrCompare added in v1.0.3

func SubstrCompare(main_str, str string, offset, length int) int

二进制安全比较字符串

func SubstrCount

func SubstrCount(s, substr string) int

SubstrCount - Count the number of substring occurrences

func SysGetTempDir

func SysGetTempDir() string

SysGetTempDir - Returns directory path used for temporary files

func System

func 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 Tan

func Tan(x float64) float64

Tan - Tangent

func Tanh

func Tanh(x float64) float64

Tanh - Hyperbolic tangent

func Ternary

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

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

func Time

func Time() int64

Time time()

func Touch

func Touch(filename string) (bool, error)

Touch touch()

func Trim

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

Trim trim()

func URLDecode

func URLDecode(str string) (string, error)

URLDecode urldecode()

func URLEncode

func URLEncode(str string) string

URLEncode urlencode()

func Ucfirst

func Ucfirst(str string) string

Ucfirst ucfirst()

func Ucwords

func Ucwords(str string) string

Ucwords ucwords()

func Umask

func Umask(mask int) int

Umask umask()

func UnderlineStringToCamel added in v1.0.3

func UnderlineStringToCamel(s string) string

*

下划线字符串转成驼峰字符串
如 abcd_a ==> abcdA

func Uniqid

func Uniqid(prefix string) string

Uniqid uniqid()

func Unlink(name string) error

Unlink - Deletes a file

func Unpack

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

Unpack unpack()

func Urldecode

func Urldecode(s string) (string, error)

Urldecode - Decodes URL-encoded string

func Urlencode

func Urlencode(s string) string

Urlencode - URL-encodes string

func Usleep

func Usleep(ms int64)

Usleep - Delay execution in microseconds

func VersionCompare

func 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 Wordwrap

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

Wordwrap wordwrap()

func ZipOpen

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

ZipOpen 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