Documentation ¶
Overview ¶
Package php implements some PHP functions
See README.md for more info.
Index ¶
- Constants
- Variables
- func Abs(number float64) float64
- func Addslashes(str string) string
- func ArrayChunk(array []interface{}, size int) [][]interface{}
- func ArrayColumn(input []map[string]interface{}, columnKey string) []interface{}
- func ArrayCombine(keys, values []interface{}) map[interface{}]interface{}
- func ArrayDiff(array1, array2 []interface{}) []interface{}
- func ArrayFilter(input interface{}, callback func(interface{}) bool) interface{}
- func ArrayFlip(input interface{}) interface{}
- func ArrayIntersect(array1, array2 []interface{}) []interface{}
- func ArrayKeyExists(k interface{}, m map[interface{}]interface{}) bool
- func ArrayKeys(input interface{}) interface{}
- func ArrayPad(array []interface{}, size int, value interface{}) []interface{}
- func ArrayPop(s *[]interface{}) interface{}
- func ArrayPush(s *[]interface{}, elements ...interface{}) int
- func ArrayReverse(s []interface{}) []interface{}
- func ArrayShift(s *[]interface{}) interface{}
- func ArraySlice(array []interface{}, offset, length uint) []interface{}
- func ArraySum(array interface{}) interface{}
- func ArrayUnique(array interface{}) interface{}
- func ArrayUnshift(s *[]interface{}, elements ...interface{}) int
- func BaseConvert(number string, frombase, tobase int) (string, error)
- func Basename(path string) string
- func Bin2hex(src []byte) string
- func Bindec(str string) (string, error)
- func Ceil(value float64) float64
- func Checkdate(month, day, year int) bool
- func Chmod(filename string, mode os.FileMode) error
- func Chown(filename string, uid, gid int) error
- func Chr(ascii int) string
- func Copy(src, dst string) error
- func Count(v interface{}) int
- func Crc32(str string) uint32
- func CtypeAlnum(text string) bool
- func CtypeAlpha(text string) bool
- func CtypeCntrl(text string) bool
- func CtypeDigit(text string) bool
- func CtypeGraph(text string) bool
- func CtypeLower(text string) bool
- func CtypePrint(text string) bool
- func CtypePunct(text string) bool
- func CtypeSpace(text string) bool
- func CtypeUpper(text string) bool
- func CtypeXdigit(text string) bool
- func Date(f string, timestamp int64) string
- func Decbin(number int64) string
- func Dechex(number int64) string
- func Decoct(number int64) string
- func DefaultNumberFormat(number float64, decimals int) string
- func Dirname(path string) string
- func DirnameWithLevels(path string, levels int) string
- func Explode(delimiter, str string) []string
- func FileExists(filename string) bool
- func FileGetContents(filename string) (string, error)
- func FilePutContents(filename string, data string) error
- func FileSize(filename string) (int64, error)
- func FirstDateOfLastMonth(t time.Time) time.Time
- func FirstDateOfMonth(t time.Time) time.Time
- func FirstDateOfNextMonth(t time.Time) time.Time
- func Floor(value float64) float64
- func GetHostByAddr(ipAddress string) (string, error)
- func GetHostByName(hostname string) (string, error)
- func GetHostByNamel(hostname string) ([]string, error)
- func GetHostName() (string, error)
- func Getenv(varname string) string
- func HTMLSpecialchars(str string) string
- func HTMLSpecialcharsDecode(str string) string
- func Hex2bin(str string) []byte
- func Hexdec(str string) (int64, error)
- func IP2Long(ipAddress string) uint32
- func Implode(glue string, pieces []string) string
- func InArray(needle interface{}, haystack interface{}) bool
- func Ireplace(search, replace interface{}, subject string) string
- func IsDir(filename string) bool
- func IsExecutable(filename string) bool
- func IsFile(filename string) bool
- func IsLeapYear(t time.Time) bool
- func IsLink(filename string) bool
- func IsReadable(filename string) bool
- func IsWritable(filename string) bool
- func KeyExists(k interface{}, m map[interface{}]interface{}) bool
- func LastDateOfMonth(t time.Time) time.Time
- func Lcfirst(str string) string
- func Link(target, link string) error
- func LocalDate(f string, timestamp int64) string
- func Long2IP(properAddress uint32) string
- func Ltrim(str string, chars ...string) string
- func Md5(str string) string
- func Md5File(filename string) (string, error)
- func MemoryGetUsage(realUsage bool) uint64
- func Microtime() float64
- func Mkdir(pathname string, mode os.FileMode, recursive bool) error
- func MtRand(min, max int) int
- func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string
- func Octdec(str string) (int64, error)
- func Ord(character string) rune
- func Pi() float64
- func Putenv(setting string) error
- func Rand(min, max int) int
- func RandomBytes(length int) []byte
- func RandomString(length int) string
- func Realpath(path string) string
- func Rename(oldname, newname string) error
- func Replace(search, replace interface{}, subject string) string
- func Rmdir(dirname string) error
- func Round(val float64, precision int) float64
- func Rsort(array interface{}) interface{}
- func Rtrim(str string, chars ...string) string
- func Sha1(str string) string
- func Sha1File(path string) (string, error)
- func SimilarText(first, second string) (count int, percent float32)
- func Sort(array interface{}) interface{}
- func StrPad(input string, padLength int, padString string, padType int) string
- func StrRepeat(input string, multiplier int) string
- func StrWordCount(str string) []string
- func Stripos(haystack, needle string) int
- func Stripslashes(str string) string
- func Stristr(haystack, needle string) string
- func Strlen(str string) int
- func Strpos(haystack, needle string) int
- func Strrev(str string) string
- func Strripos(haystack, needle string) int
- func Strrpos(haystack, needle string) int
- func Strstr(haystack, needle string) string
- func Strtolower(str string) string
- func Strtotime(str string) int64
- func Strtoupper(str string) string
- func Substr(str string, start, length int) string
- func Symlink(target, link string) error
- func Time() int64
- func Today(f string) string
- func Touch(filename string) error
- func Trim(str string, chars ...string) string
- func Ucfirst(str string) string
- func Ucname(str string) string
- func Ucwords(str string, fs ...RuneMatchFunc) string
- func Unlink(filename string) error
- type RuneMatchFunc
Constants ¶
const ( StrPadRight = iota StrPadLeft StrPadBoth )
PadTypes for StrPad
Variables ¶
var MaxPrecision = 14
MaxPrecision is the default max precision for math functions
Functions ¶
func Addslashes ¶
Addslashes quote string with slashes
The characters to be escaped are single quote ('), double quote (") and backslash (\).
func ArrayChunk ¶
func ArrayChunk(array []interface{}, size int) [][]interface{}
ArrayChunk splits an array into chunks
func ArrayColumn ¶
ArrayColumn returns the values from a single column in the input array
func ArrayCombine ¶
func ArrayCombine(keys, values []interface{}) map[interface{}]interface{}
ArrayCombine creates an array by using one array for keys and another for its values
func ArrayDiff ¶
func ArrayDiff(array1, array2 []interface{}) []interface{}
ArrayDiff computes the difference of arrays
func ArrayFilter ¶
func ArrayFilter(input interface{}, callback func(interface{}) bool) interface{}
ArrayFilter filters elements of an array using a callback function
func ArrayFlip ¶
func ArrayFlip(input interface{}) interface{}
ArrayFlip exchanges all keys with their associated values in an array
func ArrayIntersect ¶
func ArrayIntersect(array1, array2 []interface{}) []interface{}
ArrayIntersect computes the intersection of arrays
func ArrayKeyExists ¶
func ArrayKeyExists(k interface{}, m map[interface{}]interface{}) bool
ArrayKeyExists is alias of KeyExists()
func ArrayKeys ¶
func ArrayKeys(input interface{}) interface{}
ArrayKeys returns all the keys or a subset of the keys of an array
func ArrayPad ¶
func ArrayPad(array []interface{}, size int, value interface{}) []interface{}
ArrayPad pads array to the specified length with a value
func ArrayPop ¶
func ArrayPop(s *[]interface{}) interface{}
ArrayPop pops the element off the end of array
func ArrayPush ¶
func ArrayPush(s *[]interface{}, elements ...interface{}) int
ArrayPush pushes one or more elements onto the end of array, returns the new number of elements in the array.
func ArrayReverse ¶
func ArrayReverse(s []interface{}) []interface{}
ArrayReverse returns an array with elements in reverse order
func ArrayShift ¶
func ArrayShift(s *[]interface{}) interface{}
ArrayShift shifts an element off the beginning of array
func ArraySlice ¶
func ArraySlice(array []interface{}, offset, length uint) []interface{}
ArraySlice extracts a slice of the array
func ArraySum ¶
func ArraySum(array interface{}) interface{}
ArraySum returns the sum of values in an array
func ArrayUnique ¶
func ArrayUnique(array interface{}) interface{}
ArrayUnique removes duplicate values from an array
you can use type assertion to convert the result to the type of input
func ArrayUnshift ¶
func ArrayUnshift(s *[]interface{}, elements ...interface{}) int
ArrayUnshift prepends one or more elements to the beginning of a array, returns the new number of elements in the array.
func BaseConvert ¶
BaseConvert converts a number between arbitrary bases
func Copy ¶
Copy copies the src file to dst. Any existing file will be overwritten and will not copy file attributes.
func CtypeAlnum ¶
CtypeAlnum returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
func CtypeAlpha ¶
CtypeAlpha returns TRUE if every character in text is a letter, FALSE otherwise.
func CtypeCntrl ¶
CtypeCntrl returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
func CtypeDigit ¶
CtypeDigit returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
func CtypeGraph ¶
CtypeGraph returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
func CtypeLower ¶
CtypeLower returns TRUE if every character in text is a lowercase letter.
func CtypePrint ¶
CtypePrint returns TRUE if every character in text will actually create output (including blanks). returns FALSE if text contains control characters or characters that do not have any output or control function at all.
func CtypePunct ¶
CtypePunct returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
func CtypeSpace ¶
CtypeSpace returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
func CtypeUpper ¶
CtypeUpper returns TRUE if every character in text is an uppercase letter.
func CtypeXdigit ¶
CtypeXdigit returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
func Date ¶
Date returns a string formatted according to the given format string using the given integer timestamp
Note that the timezone is set to UTC
func DefaultNumberFormat ¶
DefaultNumberFormat is default NumberFormat for english notation with thousands separator
func DirnameWithLevels ¶
DirnameWithLevels returns a parent directory's path which is levels up from the current directory.
func Explode ¶
Explode returns an slice of strings, each of which is a substring of str formed by splitting it on boundaries formed by the string delimiter.
func FileExists ¶
FileExists checks whether a file or directory exists
func FileGetContents ¶
FileGetContents reads entire file into a string
func FilePutContents ¶
FilePutContents writes data to a file
func FirstDateOfLastMonth ¶
FirstDateOfLastMonth gets the first date of last month
func FirstDateOfMonth ¶
FirstDateOfMonth gets the first date of the month which the given time is in
func FirstDateOfNextMonth ¶
FirstDateOfNextMonth gets the first date of next month
func GetHostByAddr ¶
GetHostByAddr gets the Internet host name corresponding to a given IP address
func GetHostByName ¶
GetHostByName gets the IPv4 address corresponding to a given Internet host name
func GetHostByNamel ¶
GetHostByNamel gets a list of IPv4 addresses corresponding to a given Internet host name
func HTMLSpecialchars ¶
HTMLSpecialchars converts special characters to HTML entities
func HTMLSpecialcharsDecode ¶
HTMLSpecialcharsDecode converts special HTML entities back to characters
func IP2Long ¶
IP2Long converts a string containing an (IPv4) Internet Protocol dotted address into a long integer
func Implode ¶
Implode returns a string containing a string representation of all the slice elements in the same order, with the glue string between each element.
func InArray ¶
func InArray(needle interface{}, haystack interface{}) bool
InArray checks if a value exists in an array or map
needle is the element to search, haystack is the slice or map to be search
func IsExecutable ¶
IsExecutable tells whether the filename is executable
func IsLeapYear ¶
IsLeapYear checks if the given time is in a leap year
func IsReadable ¶
IsReadable tells whether a file exists and is readable
func IsWritable ¶
IsWritable tells whether the filename is writable
func KeyExists ¶
func KeyExists(k interface{}, m map[interface{}]interface{}) bool
KeyExists checks if the given key or index exists in the array
func LastDateOfMonth ¶
LastDateOfMonth gets the last date of the month which the given time is in
func LocalDate ¶
LocalDate returns a string formatted according to the given format string using the given integer timestamp
Note that the timezone is using local timezone
func Long2IP ¶
Long2IP converts an long integer address into a string in (IPv4) Internet standard dotted format
func MemoryGetUsage ¶
MemoryGetUsage returns the amount of allocated memory in bytes. Set realUsage to TRUE to get total memory allocated from system, including unused pages. If realUsage is FALSE then only the used memory is reported.
func Microtime ¶
func Microtime() float64
Microtime returns current Unix timestamp with microseconds
func NumberFormat ¶
NumberFormat formats a number with grouped thousands
decimals: sets the number of decimal points. decPoint: sets the separator for the decimal point. thousandsSep: sets the thousands separator.
func Putenv ¶
Putenv sets the value of an environment variable. The setting should be a key-value pair, like "FOO=BAR"
func RandomBytes ¶
RandomBytes generates cryptographically secure pseudo-random bytes
func RandomString ¶
RandomString generates cryptographically secure pseudo-random bytes and return its hexadecimal representation
func Replace ¶
Replace all occurrences of the search string with the replacement string
This function is an implement of PHP's str_replace
func Round ¶
Round returns the rounded value of val to specified precision (number of digits after the decimal point)
Note that we limit the range of precision to [-14, 14] by default
func Rsort ¶
func Rsort(array interface{}) interface{}
Rsort sorts an array in reverse order (highest to lowest)
func SimilarText ¶
SimilarText calculate the similarity between two strings returns the number of matching chars in both strings and the similarity percent note that there is a little difference between the original php function that a multi-byte character is counted as 1 while it would be 2 in php
func StrWordCount ¶
StrWordCount returns an array containing all the words found inside the string
func Stripos ¶
Stripos find position of the first occurrence of a case-insensitive substring in a string
func Strpos ¶
Strpos find position of first occurrence of string in a string
It's multi-byte safe. return -1 if can not find the substring
func Strripos ¶
Strripos find the position of the last occurrence of a case-insensitive substring in a string
func Strtotime ¶
Strtotime parses any English textual datetime description into a Unix timestamp, default timezone is UTC if you do not specify one
e.g. You can specify the timezone to UTC+8 by using yyyy-MM-ddThh:mm:ss+08:00
Returns a timestamp on success, -1 on failure.
Note that this function does not fully cover PHP's strtotime function yet
func Substr ¶
Substr returns the portion of string specified by the start and length parameters.
The behaviour of this function is mostly the same as the PHP mb_substr function,
see http://php.net/manual/en/function.mb-substr.php
except that:
1) If start or length is invalid, empty string will be return;
2) If length is 0, the substring starting from start until the end of the string will be returned.
func Today ¶
Today returns a string formatted according to the given format string using current timestamp
Note that the timezone is using local timezone
func Ucwords ¶
func Ucwords(str string, fs ...RuneMatchFunc) string
Ucwords uppercases the first character of each word in a string
Types ¶
type RuneMatchFunc ¶
RuneMatchFunc is function to check if a rune match some condition