php常用方法

php中处理字符串的相关方法

  • 将日期时间字符串转化为整形(时间戳)
    strtotime() 函数将任何英文文本的日期或时间描述解析为 Unix 时间戳
 
  • 将UNIX时间戳转换为日期用函数: date()
  
  • 将数组转化成字符串
    implode() 函数返回由数组元素组合成的字符串。
  
结果:Hello World! I love Shanghai!
  • explode() 函数把字符串打散为数组。
 
结果:Array ( [0] => Hello [1] => world. [2] => I [3] => love [4] => Shanghai! )
  • substr_count() 函数计算子串在字符串中出现的次数
$str = "123-123-434-2";
$num = substr_count($str,"-"); //返回值为3
  • str_repeat() 函数把字符串重复指定的次数

php中数组常用方法

  • array_merge() 函数把一个或多个数组合并为一个数组。
 red [1] => green [2] => blue [3] => yellow )
?>

你可能感兴趣的:(php常用方法)