# README
HELPERS
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.
# Functions
Abs abs().
Acos - Arc cosine.
Acosh - Inverse hyperbolic cosine.
Addcslashes - Quote string with slashes in a C style.
Addslashes addslashes().
Array - Create an array.
No description provided by the author
ArrayChunk array_chunk().
ArrayColumn array_column() ArrayColumn — Return the values from a single column in the input array.
No description provided by the author
No description provided by the author
ArrayCombine array_combine().
ArrayCountValues — Counts all the values of an array.
No description provided by the author
ArrayFill array_fill().
ArrayFillKeys - Fill an array with values, specifying keys.
ArrayFlip - Exchanges all keys with their associated values in an array.
ArrayIntersect — Computes the intersection of arrays.
ArrayKeyExists array_key_exists().
No description provided by the author
*
* array_key_first — Gets the first key of an array
* @params map[interface{}]interface{} array An array.
*
* array_key_first — Gets the first key of an array
* @params map[interface{}]interface{} array An array.
ArrayKeys array_keys().
key的类型为int.
key的类型为interface{}.
ArrayMerge array_merge().
对于切片不建议使用本方法,而要直接使用 append.
ArrayPad array_pad().
ArrayPop array_pop() Pop the element off the end of slice.
ArrayPush - Push one or more elements onto the end of array.
ArrayRand array_rand().
ArrayReverse array_reverse().
No description provided by the author
No description provided by the author
ArrayShift array_shift() Shift an element off the beginning of slice.
ArraySlice array_slice().
ArrayUnshift array_unshift() Prepend one or more elements to the beginning of a slice.
ArrayValues array_values().
Asin - Arc sine.
Asinh - Inverse hyperbolic sine.
Atan - Arc tangent.
Atan2 - Arc tangent of two variables.
Atanh - Inverse hyperbolic tangent.
Base64Decode - Decodes data encoded with MIME base64.
Base64Encode - Encodes data with MIME base64.
BaseConvert - Convert a number between arbitrary bases.
Basename - Returns trailing name component of path.
Bin2hex bin2hex().
Bindec bindec().
Boolval - Get the boolean value of a variable.
*
驼峰字符串转成下划线+小些字母
例如: abcdAccc ==> abcd_accc
AbcdA ==> abcd_a
如果遇到有大写字母的地方,则将在前一位将加上下划线 "_", 将大写字母转成小字母(如果是首字母,则只是转成小谢即可)
*/.
Ceil - Round fractions up.
Chdir - Change directory.
Checkdate - Validate a Gregorian date.
Chgrp - Changes file group.
Chmod chmod().
Chown chown().
Chr - Return a specific character.
ChunkSplit - Split a string into smaller chunks.
Closedir - Close directory's handle.
Copy copy().
Cos - Cosine.
Cosh - Hyperbolic cosine.
Count - Count all elements in an array, or something in an object.
Crc32 crc32().
dateTimeFormat 格式如:"2006-01-02 15:04:05".
多少分钟后.
DateAdd - Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object.
多少秒后.
多少秒前.
多少天后.
多少天前.
多少小时后.
多少小时前.
多少分钟前.
当前日期.
dateTimeFormat 格式如:"2006-01-02 15:04:05".
多少秒后.
多少秒前.
多少天后.
多少天前.
多少小时后.
多少小时前.
多少分钟后.
多少分钟前.
当前日期时间.
当前日期时间.
明天时间.
当前日期.
明天日期.
Decbin - Decimal to binary.
Dechex - Decimal to hexadecimal.
Decoct - Decimal to octal.
Delete delete().
Die die().
Dirname - Returns a parent directory's path.
DiskFreeSpace disk_free_space().
DiskTotalSpace disk_total_space().
Echo - Output one or more strings.
Empty - Determine whether a variable is empty.
Exec - Execute an external program.
Exit exit().
Exp - Calculates the exponent of e.
Explode explode().
Expm1 - Returns exp(number) - 1 computed in a way that is accurate even when the value of number is close to zero.
Fclose fclose().
Fgetcsv fgetcsv().
FileExists file_exists().
No description provided by the author
No description provided by the author
FileGetContents file_get_contents().
Filemtime filemtime() 获取文件修改时间 返回unix时间戳.
FilePutContents file_put_contents().
FileSize filesize().
Floor - Round fractions down.
Getcwd getcwd().
Getenv getenv().
*
获取当前环境
*/.
Gethostbyaddr gethostbyaddr() Get the Internet host name corresponding to a given IP address.
Gethostbyname gethostbyname() Get the IPv4 address corresponding to a given Internet host name.
Gethostbynamel gethostbynamel() Get a list of IPv4 addresses corresponding to a given Internet host name.
Gethostname gethostname().
GetHtmlTranslationTable - Returns the translation table used by htmlspecialchars() and htmlentities().
No description provided by the author
Gettype - Get the type of a variable.
Glob - Find pathnames matching a pattern.
Hex2bin hex2bin().
Hexdec hexdec().
将字符转换为 HTML 转义字符.
No description provided by the author
HTMLEntityDecode html_entity_decode().
Htmlspecialchars - Convert special characters to HTML entities.
HtmlspecialcharsDecode - Convert special HTML entities back to characters.
HTTPBuildQuery http_build_query().
Implode implode().
InArray in_array() haystack supported types: slice, array or map.
Intval - Get the integer value of a variable.
IP2long ip2long() IPv4.
IsBool - Finds out whether a variable is a boolean.
IsDir is_dir().
IsFile is_file().
IsFinite - Finds whether a value is a legal finite number.
IsInfinite - Finds whether a value is infinite.
IsNan - Finds whether a value is not a number.
IsNumeric - Finds whether a variable is a number or a numeric string.
IsReadable is_readable().
IsWritable - Tells whether the filename is writable.
IsWriteable is_writeable().
Join - Alias of implode().
JsonDecode - Decodes a JSON string.
JSONDecode json_decode().
JsonEncode - Returns the JSON representation of a value.
JSONEncode json_encode().
Lcfirst lcfirst().
Levenshtein levenshtein() costIns: Defines the cost of insertion.
Log - Natural logarithm.
Log10 - Base-10 logarithm.
Log1p - Returns log(1 + number) computed in a way that is accurate even when the value of number is close to zero.
Long2ip long2ip() IPv4.
Ltrim ltrim().
*
将map下的所有键 由驼峰转成下划线
*/.
No description provided by the author
No description provided by the author
No description provided by the author
*
将map下的所有键 由下划线转成驼峰
*/.
Max max().
MbStrlen - Get string length.
MbSubstr - Get part of string.
Md5 - Calculate the md5 hash of a string.
Md5File md5_file().
MemoryGetUsage memory_get_usage() return in bytes.
Min min().
Mkdir - Makes directory Mkdir mkdir().
No description provided by the author
Nl2br - Inserts HTML line breaks before all newlines in a string.
NumberFormat number_format() decimals: Sets the number of decimal points.
Octdec Octdec().
Ord ord().
Pack pack().
No description provided by the author
ParseUrl - Parse a URL and return its components.
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.
Passthru passthru() returnVar, 0: succ; 1: fail.
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).
Pi - Get value of pi.
Pow - Exponential expression.
Print - Output a string.
PrintR - Prints human-readable information about a variable.
Putenv putenv() The setting, like "FOO=BAR".
Quotemeta quotemeta().
Rand rand() Range: [0, 2147483647].
Rawurldecode - Decodes URL-encoded string.
Rawurlencode - URL-encode according to RFC 3986.
Realpath - Returns canonicalized absolute pathname.
Rename - Renames a file or directory.
Rmdir — Removes directory.
Round - Rounds a float.
Rtrim rtrim().
scandir — List files and directories inside the specified path.
Sha1 - Calculate the sha1 hash of a string.
Sha1File sha1_file().
SimilarText similar_text().
Sin - Sine.
Sinh - Hyperbolic sine.
Sleep - Delay execution.
Soundex soundex() Calculate the soundex key of a string.
Sqrt - Square root.
Stat - Gives information about a file.
No description provided by the author
Stripos stripos().
Stripslashes stripslashes().
StripTags - Strip HTML and PHP tags from a string.
Strlen - Get string length.
StrPad - Pad a string to a certain length with another string.
Strpos strpos().
Strrchr - Find the last occurrence of a character in a string.
StrRepeat - Repeat a string.
StrReplace str_replace().
Strrev strrev().
Strripos strripos().
Strrpos strrpos().
StrShuffle str_shuffle().
Strstr strstr().
Strtolower strtolower().
Strtotime strtotime() Strtotime("02/01/2006 15:04:05", "02/01/2016 15:04:05") == 1451747045 Strtotime("3 04 PM", "8 41 PM") == -62167144740.
例如:2019-01-31 00:00:00.
例如:2019-01-31.
例如:2019-01-31 00:00:00.
Strtoupper strtoupper().
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.
Strval - Get string value of a variable.
StrWordCount str_word_count().
Substr substr().
二进制安全比较字符串.
SubstrCount - Count the number of substring occurrences.
SysGetTempDir - Returns directory path used for temporary files.
System system() returnVar, 0: succ; 1: fail Returns the last line of the command output on success, and "" on failure.
Tan - Tangent.
Tanh - Hyperbolic tangent.
Ternary Ternary expression max := Ternary(a > b, a, b).(int).
Time time().
Touch touch().
Trim trim().
Ucfirst ucfirst().
Ucwords ucwords().
Umask umask().
*
下划线字符串转成驼峰字符串
如 abcd_a ==> abcdA
*/.
Uniqid uniqid().
Unlink - Deletes a file.
Unpack unpack().
Urldecode - Decodes URL-encoded string.
URLDecode urldecode().
Urlencode - URL-encodes string.
URLEncode urlencode().
Usleep - Delay execution in microseconds.
VersionCompare version_compare() The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively.
Wordwrap wordwrap().
ZipOpen zip_open().
# Variables
转为小写.
转为大写.
No description provided by the author
No description provided by the author
结果为INT.
结果为INT64.
结果为STRING.