zoukankan      html  css  js  c++  java
  • php中各种操作字符串和时间戳的代码关键词

    <?php
    /**
    * Created by 郭鹏.
    * User: msi
    * Date: 2017/9/27
    * Time: 14:17
    */

    //随机数生成器
    echo rand();
    echo "<br>";
    //生成某个范围随机数
    echo rand(0,10);
    echo "<br>";
    //获取当前时间戳
    echo time();
    echo "<br>";
    //格式化显示时间
    echo "<br>";
    echo date("Y-m-d H:i:s",time());
    echo "<br>";
    echo date("Y-m-d H:i:s","1506494976");
    //字符串转换成时间戳
    echo "<br>";
    echo strtotime("2017-09-27 14:37:39");
    echo "<br>";

    //取字符串的长度
    $str1 = "abcdefg";
    $str2 = "abc";
    //echo strlen();
    echo "<br>";
    //比较两个字符串,美国信息交换标准代码;
    var_dump(strcmp($str1,$str2));
    //转小写
    echo "<br>";
    strtolower($str2);
    //转大写
    //strtoupper();
    //拆分字符串
    echo "<br>";
    var_dump(explode("b",$str2));

    //将数组元素拼接成一个字符串
    echo "<br>";
    echo implode("|",["a","b","c"]);

    //替换替换
    echo "<br>";
    //这里拿到是返回值,所以要用到echo输出一下;
    echo str_replace("cd","CD",$str1);
    echo "<br>";
    echo $str1;

    //替换指定位置的字符串
    echo "<br>";
    echo substr_replace($str1,"xxx",0,3);

    //截取字符串
    echo "<br>";
    echo substr($str1,1,3);

    //正则表达式
    $str =<<<A
    456abcdefghijklmn123
    A;
    echo "<br>";
    //上述所有字符的数字替换成#
    echo preg_replace("/d/","#",$str);

    echo "<br>";$zxc = <<<askadjkasdkasjdaklsdnkas123a;echo preg_replace("/d/","#",$zxc);
    echo "<br>";
    echo substr($zxc,3,10);
    echo "<br>";
    echo substr_replace($zxc,"skazxc",1,6);
    echo "<br>";
    echo substr($zxc,1,6);
    echo "<br>";echo $zxc;
    echo substr_replace();
  • 相关阅读:
    leetcode 203
    vim插件管理器vundle
    centos7看电影
    getopt
    iOS/object-c: 枚举类型 enum,NS_ENUM,NS_OPTIONS
    "ALView+PureLayout.h"
    UIPageViewController教程
    (Mac ox 10.11+) CocoaPods安装,卸载,使用说明
    CocoaPods集成到Xcode项目中的步骤
    label_设置行距、字距及计算含有行间距的label高度
  • 原文地址:https://www.cnblogs.com/GP1014336455/p/7675871.html
Copyright © 2011-2022 走看看