加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

几个函数

发布时间:2020-12-14 22:55:33 所属栏目:大数据 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 ----常用公共函数库--local FUNC = {}--to intFUNC.int = function(sString) local iNum = tonumber(sString) iNum = ((iNum == nil) and tonumber(0)

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

--
--常用公共函数库
--
local FUNC = {}

--to int
FUNC.int = function(sString)
    local iNum = tonumber(sString)
    iNum = ((iNum == nil) and tonumber(0)) or iNum
    return iNum
end


--将字符串分割成数组,同php: explode
FUNC.explode = function(szFullString,szSeparator)  
    local nFindStartIndex = 1  
    local nSplitIndex = 1  
    local nSplitArray = {}  
    while true do  
        local nFindLastIndex = string.find(szFullString,szSeparator,nFindStartIndex)  
        if not nFindLastIndex then  
            nSplitArray[nSplitIndex] = string.sub(szFullString,nFindStartIndex,string.len(szFullString))  
            break  
        end  
        nSplitArray[nSplitIndex] = string.sub(szFullString,nFindLastIndex - 1)  
        nFindStartIndex = nFindLastIndex + string.len(szSeparator)  
        nSplitIndex = nSplitIndex + 1  
    end  
    return nSplitArray  
end  

--将日期转换为时间戳,date(Y-m-d H:i:s) 同php strtotime,只支持 1970-01-01 08:00:00 格式
--返回时间戳
FUNC.strtotime = function(sDate)
    local iTime = 0
    
    if 0 == string.len(sDate) then 
        return iTime
    end
    local sDateymd = string.sub(sDate,1,10)
    local sDatehis = string.sub(sDate,12,-1)
    local aDateymd = FUNC.explode(sDateymd,'-')
    local aDatehis = FUNC.explode(sDatehis,':')
    local Y,m,d = aDateymd[1],aDateymd[2],aDateymd[3]
    local H,i,s = aDatehis[1],aDatehis[2],aDatehis[3]
    iTime = os.time({year=Y,month=m,day=d,hour=H,min=i,sec=s})
    return iTime
end

return FUNC

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读