码迷,mamicode.com
首页 > Web开发 > 详细

php对字符串的操作4之 字符串的格式化函数

时间:2018-05-09 19:30:12      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:特殊   mat   lsp   str   sha   color   函数   md5   分享图片   

strtolower($str )

strtoupper($str )

大小写转换

 

strtotime(‘2018-1-1 0:0‘)

字符串转时间戳

 

date(‘Y-m-d H:i:s‘,time())

格式化时间戳

 

md5()

加密

 

trim()

移除字符串两侧的空白字符(可特指)。

 

strip_tags()

过滤(删除)html标签(可特指保留)

 

htmlspecialchars()

将特殊字符(标签)转换为html实体(非标签)

htmlspecialchars_decode

还原

 

<?php
//大小写转换
$str = ‘WWW.BAIDU.COM‘;
echo $str = strtolower($str ),‘<hr>‘;
echo $str = strtoupper($str ),‘<hr>‘;

//字符串转时间戳
date_default_timezone_set(‘PRC‘); //设置默认时区
echo $chuo = strtotime(‘2018-1-1 0:0‘),‘<hr>‘;
//格式化时间戳
echo date(‘Y-m-d H:i:s‘,$chuo),‘<hr>‘;
echo date(‘Y-m-d H:i:s‘,time()),‘<hr>‘;

//千位分隔符函数
$num = 123456789.125;
echo number_format($num,2),‘<hr>‘;

//加密
echo md5(md5(123456)),‘<hr>‘;
echo sha1(123456),‘<hr>‘;

//trim() 移除字符串两侧的空白字符。
$test = ‘   都京都都‘;
echo trim($test),‘<hr>‘;
//去除右边的‘都‘字符
echo rtrim($test,‘都‘),‘<hr>‘;

//过滤html标签
$html = ‘<b><h1>你好</h1></b>‘;
//<b>标签选择保留
echo $html,‘---‘,strip_tags($html,‘<b>‘),‘<hr>‘;

//将特殊字符转换为html实体
$htm = ‘<b><h1>你好</h1></b>‘;
echo $htm = htmlspecialchars($htm),‘<hr>‘;
//现在将其逆向处理
echo $htm = htmlspecialchars_decode($htm);
?>

技术分享图片

 

php对字符串的操作4之 字符串的格式化函数

标签:特殊   mat   lsp   str   sha   color   函数   md5   分享图片   

原文地址:https://www.cnblogs.com/cl94/p/9015773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!