PHP 常用函数 待续 ......

is_numeric        检测变量是否为数字或数字字符串
array_search    数组中检索值,并返回键名
strrpos              在字符串中最后一次出现的位置
parse_url          解析url函数
in_array("Mark", $people)
foreach ($zparr as $key => $value)
str_pad() 函数把字符串填充为新的长度。str_pad($d,2,"0",STR_PAD_LEFT)
explode(",",$arr)    把字符串打散为数组
implode(",",$arr);     把数组元素组合为字符串
$result=array_flip($a1);      反转数组中所有的键以及它们关联的值
str_replace("world","Shanghai","Hello world!");把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai"
strpos($v,"周一") 查找字符串出现次
移除数组中重复的值:array_unique($a)
数组去除空值--用回调函数过滤数组中的单元
array_filter(explode(",",$str));
strip_tags($value)  过滤html
直接取整,舍弃小数,保留整数:intval()
四舍五入取整:round()                      round(3.14159);
向上取整,有小数就加1:ceil()           ceil(3.14159)
向下取整:floor()                               floor(3.14159);
保留两位小数 sprintf("%.2f",$num)
日期加一天 strtotime("+1 day",time())   加一个月strtotime("+1 month",time())   加一年strtotime("+1 year",time())
strtotime($t);
date('Y-m-d H:i:s',$t)

 

$html = file_get_contents('http://www.');
$pattern="/<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\">(.*?)<\/table>/si";
preg_match($pattern,$html,$tablebox);
$guhaotemp = array();
if($tablebox[0]){
    $str = preg_replace( '#\s{2,}#', '', $tablebox[0]);
    $str = preg_replace("/<p style=\"color:#999;\">(.*?)<\/p>/i","",$str);
    preg_match_all('/<tr>(.*?)<\/tr>/si',$str,$trtemp);
    foreach ($trtemp[0] as $key => $value) {
        if(!$key){
            preg_match_all('/<th>(.*?)<\/th>/si',$value,$tdtemp);
            $guhaotemp[] = $tdtemp[0];
        }
        else{
            preg_match_all('/<td>(.*?)<\/td>/si',$value,$tdtemp);
            $guhaotemp[] = $tdtemp[0];
        }
    }
}

for ($x=0; $x<=20; $x++) {
    $t = strtotime("-".$x." day",time());
    $datetime = date('Y-m-d',$t).' '.str_pad(rand(7,22),2,"0",STR_PAD_LEFT).':'.rand(10,59).':'.rand(10,59);
    echo strtotime($datetime).'<br>';
    echo $datetime.'<br><br>';

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值