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 Base64Decode(data string) (string, error)
- func Base64Encode(data string) string
- 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 Chdir(dir string) error
- 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 DateAdd(t time.Time, d time.Duration) time.Time
- func DateCreate(str string) (time.Time, error)
- func DateCreateFromFormat(f string, t string) (time.Time, error)
- func DateCreateFromFormatLocation(f string, t string, loc *time.Location) (time.Time, error)
- func DateDateSet(year, month, day int) (time.Time, error)
- func DateDefaultTimezoneGet() string
- func DateDefaultTimezoneSet(tz string) error
- func DateDiff(t1 time.Time, t2 time.Time) time.Duration
- func DateFormat(t time.Time, f string) string
- func DateISODateSet(year, week, day int) (time.Time, error)
- func DateIntervalCreateFromDateString(str string) (time.Duration, error)
- func DateModify(t time.Time, modify string) (time.Time, error)
- func DateOffsetGet(t time.Time) int
- func DateSub(t time.Time, d time.Duration) time.Time
- func DateTimestampGet(t time.Time) int64
- func DateTimestampSet(timestamp int64) time.Time
- func DateTimezoneGet(t time.Time) string
- func DateTimezoneSet(t time.Time, tz string) (time.Time, error)
- 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 GetHeaders(url string) (http.Header, error)
- func GetHostByAddr(ipAddress string) (string, error)
- func GetHostByName(hostname string) (string, error)
- func GetHostByNamel(hostname string) ([]string, error)
- func GetHostName() (string, error)
- func GetMetaTags(url string) (map[string]string, error)
- func Getcwd() string
- func Getenv(varname string) string
- func HTMLSpecialchars(str string) string
- func HTMLSpecialcharsDecode(str string) string
- func HTTPBuildQuery(data map[string]interface{}) 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 JSONDecode(jsonStr string, v interface{}) error
- func JSONEncode(value interface{}) (string, error)
- 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 ParseDocument(doc io.Reader) map[string]string
- func ParseURL(str string) (*url.URL, error)
- 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 RawURLDecode(str string) string
- func RawURLEncode(str string) 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 Scandir(dir string) ([]string, error)
- 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 URLDecode(str string) string
- func URLEncode(str 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 ImageInfo
- 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, returns nil if size < 1
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, if the input is not a slice or empty then return the original input
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 Base64Decode ¶
Base64Decode decodes data encoded with MIME base64. Returns error if data is in invalid format.
func Base64Encode ¶
Base64Encode encodes data with MIME base64
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 DateAdd ¶
DateAdd adds an amount of days, months, years, hours, minutes and seconds to the time t
func DateCreate ¶
DateCreate parses a date/time string and return a time.Time. Supported Date and Time Formats: https://www.php.net/manual/en/datetime.formats.php
func DateCreateFromFormat ¶
DateCreateFromFormat parses a date/time string according to a specified format
func DateCreateFromFormatLocation ¶
DateCreateFromFormatLocation parses a date/time string according to a specified format with location
func DateDateSet ¶
DateDateSet sets the date by year, month and day
func DateDefaultTimezoneGet ¶
func DateDefaultTimezoneGet() string
DateDefaultTimezoneGet gets the default timezone
func DateDefaultTimezoneSet ¶
DateDefaultTimezoneSet sets the default timezone
func DateFormat ¶
DateFormat returns a string formatted according to the given format string using the given time
func DateISODateSet ¶
DateISODateSet sets a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates
func DateIntervalCreateFromDateString ¶
DateIntervalCreateFromDateString returns a time.Duration from the given string
func DateModify ¶
DateModify alter the time by the given format
func DateSub ¶
DateSub subtracts an amount of days, months, years, hours, minutes and seconds from the time t
func DateTimestampGet ¶
DateTimestampGet gets the Unix timestamp
func DateTimestampSet ¶
DateTimestampSet sets the date and time based on an Unix timestamp
func DateTimezoneGet ¶
DateTimezoneGet gets the timezone of the given time
func DateTimezoneSet ¶
DateTimezoneSet returns a copy of t with the given timezone
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 GetHeaders ¶
GetHeaders fetches all the headers sent by the server in response to an HTTP request
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 GetMetaTags ¶
GetMetaTags extracts all meta tag content attributes from http content and returns an array
func Getcwd ¶
func Getcwd() string
Getcwd gets the current working directory, it will return empty string when error occurs
func HTMLSpecialchars ¶
HTMLSpecialchars converts special characters to HTML entities
func HTMLSpecialcharsDecode ¶
HTMLSpecialcharsDecode converts special HTML entities back to characters
func HTTPBuildQuery ¶
HTTPBuildQuery generate URL-encoded query string
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 JSONDecode ¶
JSONDecode decodes a JSON string and stores the result in the value pointed to by v
Be aware that this is different with php json_decode
func JSONEncode ¶
JSONEncode returns a string containing the JSON representation of the supplied value
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 ParseDocument ¶
ParseDocument parses a document for meta data
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 RawURLDecode ¶
RawURLDecode decodes URL-encoded string.
RawURLDecode is identical to URLDecode except that it does not unescape '+' to ' ' (space).
func RawURLEncode ¶
RawURLEncode is URL-encode according to RFC 3986.
RawURLEncode is identical to URLEncode except that it does not escape space to +.
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
This function is case sensitive
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 URLDecode ¶
URLDecode decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character.
func URLEncode ¶
URLEncode returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.
func Ucwords ¶
func Ucwords(str string, fs ...RuneMatchFunc) string
Ucwords uppercases the first character of each word in a string
Types ¶
type ImageInfo ¶
ImageInfo stores the info of an image
func GetImageSize ¶
GetImageSize gets the size of an image
func GetImageSizeFromString ¶
GetImageSizeFromString gets the size of an image from a string
type RuneMatchFunc ¶
RuneMatchFunc is function to check if a rune match some condition