Home > Article > Backend Development > Basic usage of php built-in functions
In fact, these contents can be learned in the php manual, but many php beginners do not know how to read the php manual and cannot understand it
So Aiwei.com will now explain the built-in functions of php
There are functions related to case conversion
Text html tag processing function
Case related functions
The code is as follows:
strtolower() strtoupper() ucfirst() ucword()
HTML tag related The string formatting function
code is as follows:
nl2br() htmllentities() htmlspecialchars () stripslashes () strip_tags() number_format () strrev() md5()
All string processing functions in php do not modify the original string, but return a newly formatted The string
code is as follows:
*/ //nl2br把空格转换成实体当你输入
因为一般在浏览器里显示的换行都是
例如在表单留言本里必须要转换不然折行不成功 再多的空格都任务是一个空格 $a=' i love you '; echo $a; echo nl2br($a); 结果1:i love you 结果2: i love you //表单提交如果你不进行html标签处理那么就会直接显示样式或者js代码直接运行 /*
有的复制的文章自身有标签样式就会打乱你的 页面布局 可能css冲突 htmllentities()函数用户和htmlspecialchars()相反用法就不说了 当你需要那个标签留着可以用到strip_tags()函数 echo strip_tags($_GET['title'],'
没有了
/*
加入输入i love 'jb51';
提交结果为 i love \'jb51\'反斜杠转义了
那么我要想原文输出怎么办呢
可以用这个php函数stripslashes()
取消转义
echo stripslashes($_GET['title']);
结果是i love 'jb51';
如果含有html标签呢如这种
i love 'jb51'
我要原型输出怎么办 可以用2个函数结合起来用 我已经说过的
echo htmlspecialchars(stripslashes($_GET['title']));
结果:i love 'jb51'
*/
//number_format()这个函数是格式化货币函数 不同国家的习惯不一样那么需要的货币显示就不一样例如商城中国钱是通常是这样的格式
千分位分割用逗号 保留几位用点 人称‘小数点'
这个函数的用法很简单
number_format($money,小数点保留几位,'小数点用什么分开','千分位用什么分开')
$price='123465789.233';
echo number_format($money,2,',','.');
结果:123.465.789,23
echo number_format($money,2,'.',',');//中国式的
结果:123,465,789.23
//strrev()使字符串反倒过来
$str='http://www.jb51.net';
echo strrev($str);
结果:moc.tenwii.www//:ptth
//md5就是加密 用户名密码必须要加密防止黑客
$a='admin';
echo $b= md5($a); The above is the detailed content of Basic usage of php built-in functions. For more information, please follow other related articles on the PHP Chinese website!');
提交结果是你查看源码 就会发现