phpgo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 11 Imported by: 0

README

phpgo

PHP有很多方便的函数,GO里面没有或者命名和PHP不一样,为了方便PHP转GO的同学方便,特写了本项目。

项目里面的所有函数命名都是和PHP函数一致,仅仅是首字母大写,下划线_去掉。仅支持go mod

使用方法

import "github.com/lewjian/phpgo"

phpgo.InArray("a", []string{"a"})

进度

  • 常用string函数
  • 常用array函数
  • todo

Documentation

Index

Constants

View Source
const (
	StrPadLeft = iota
	StrPadRight
	StrPadBoth
)

Variables

This section is empty.

Functions

func ArraySum

func ArraySum(data []int) int64

ArraySum 计算数组之和

func ArrayUnique

func ArrayUnique(arrayData interface{}) interface{}

ArrayUnique 切片去重,目前仅支持int和string两种类型

func Bin2Hex

func Bin2Hex(binData []byte) string

Bin2Hex 将二进制数据转为16进制字符串

func Explode

func Explode(separator, str string) []string

Explode 用一个字符串separator分割另外一个字符串str

func Hex2Bin

func Hex2Bin(s string) ([]byte, error)

Hex2Bin 将16进制字符串转为byte数组

func Implode

func Implode(separator string, data []string) string

Implode 切片转为指定字符串连接的为字符串

func InArray

func InArray(item interface{}, arrayData interface{}) bool

InArray PHP对应的in_array函数,支持int,string,float的判断

func InArrayInt

func InArrayInt(n int, nums []int) bool

InArrayInt php in_array 整数版本

func InArrayString

func InArrayString(s string, data []string) bool

InArrayString php in_array字符串版本

func Join

func Join(separator string, data []string) string

Join 切片转为指定字符串连接的为字符串

func LCFirst

func LCFirst(s string) string

LCFirst 首字母小写写

func LTrim

func LTrim(str, deleteStr string) string

LTrim 去除字符串左边指定字符串

func MD5

func MD5(data []byte) string

MD5 计算md5值

func RTrim

func RTrim(str, deleteStr string) string

RTrim 去除字符串右边边指定字符串

func Sha1

func Sha1(data []byte) string

Sha1 计算sha1值

func StrCMP

func StrCMP(s1, s2 string) int

StrCMP 字符串比较,相等返回0,s1<s2,返回-1,s1>s2,返回1

func StrContains

func StrContains(str, subStr string) bool

StrContains 判断是否某一个字符串包含一个子串

func StrEndsWith

func StrEndsWith(s, suffixStr string) bool

StrEndsWith 检查一个字符串是否以某个子串结尾

func StrIPos

func StrIPos(s, subStr string) int

StrIPos 查找字符串首次出现的位置(不区分大小写)

func StrIReplace

func StrIReplace(searchStr, replaceStr, findInStr string) (string, error)

StrIReplace 大小写忽略的字符串替换

func StrLen

func StrLen(s string) int

StrLen 获取字符串长度

func StrPad

func StrPad(str string, padLen int, padStr string, padType int) string

StrPad 使用另一个字符串填充字符串为指定长度

func StrPos

func StrPos(s, subStr string) int

StrPos 查找字符串首次出现的位置(区分大小写)

func StrRIPos

func StrRIPos(s, subStr string) int

StrRIPos 查找字符串最后出现的位置(不区分大小写)

func StrRPos

func StrRPos(s, subStr string) int

StrRPos 查找字符串最后出现的位置(区分大小写)

func StrRepeat

func StrRepeat(s string, count int) string

StrRepeat 重复一个字符串

func StrReplace

func StrReplace(search, repl, replaceIn string) string

StrReplace 字符串替换

func StrRev

func StrRev(s string) string

StrRev 字符串翻转,按照字符翻转,不是按照字节

func StrShuffle

func StrShuffle(s string) string

StrShuffle 随机打乱一个字符串

func StrSplit

func StrSplit(s string, splitLen int) []string

StrSplit 将字符串转为切片(slice),按照splitLen个字符为一个单位。 原来PHP里面是按照字节切割,这里换成了按照字符切割

func StrStartWith

func StrStartWith(s, prefix string) bool

StrStartWith 检查某个字符传s是否以prefix开始

func StrStr

func StrStr(s, substr string, needBefore bool) string

StrStr 查找字符串首次出现前(后)的字符串 如果needBefore为true表示需要substr首次出现之前的字符串,否则为之后的字符串

func StrToLower

func StrToLower(s string) string

StrToLower 字符串转为小写

func StrToUpper

func StrToUpper(s string) string

StrToUpper 字符串转为大写

func StripTags

func StripTags(src string) string

StripTags 从字符串中去除 HTML 标签

func SubStr

func SubStr(s string, start, length int) string

SubStr 字符串截取,需要注意是否越界,这是按照字节截取的

func SubStrRune

func SubStrRune(s string, start, length int) string

SubStrRune 字符串截取,需要注意是否越界,这是按照字符截取的

func Trim

func Trim(str string) string

Trim 删除字符串前后空白符

func UCFirst

func UCFirst(s string) string

UCFirst 首字母大写

func UCWords

func UCWords(s string) string

UCWords 将字符串中每个单词的首字母转换为大写

Types

This section is empty.

Jump to

Keyboard shortcuts

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