php基础教程 php内置函数实例教程_php基础
所以爱微网现在讲解先php内置函数
有大小写转换相关函数
文本html标签处理函数
大小写有关函数
strtolower()
strtoupper()
ucfirst()
ucword()
HTML标签相关的字符串格式化函数
nl2br()
htmllentities()
htmlspecialchars()
stripslashes()
strip_tags()
number_format()
strrev()
md5()
在php中所有字符串处理函数 ,都不是在原字符串上修改,而是返回一个新格式化后的字符串
//转换成小写
$a='www.jb51.net';
echo strtolower($a);
//结果:www.jb51.net
//转换成大写
$a='www.jb51.net';
echo strtoupper($a);
//结果:WWW.jb51.net
//首字母大写
$a='www.jb51.net';
echo ucfirst($a);
//结果:Www.jb51.net
//每个单词首字母大写
$a='i love you';
echo ucword($a);
//结果:I Love You
/*
提示:大家都知道大小写,认为小写和大写有区别吗,但是为什么要区分大小写呢
在win系统下php大小写不严格 但是在linux系统下就严禁拉 大小写不能乱写
比如
在自动加载类的时候
function _autoload($className){
include strtolower($className).'.class.php';
}
$obj= new MyClass;
这样就加载myclass.class.php
因为文件名常是小写那么必须转换小写
?>
*/
//nl2br把空格转换成实体
因为一般在浏览器里显示的换行都是
例如在表单留言本里必须要转换不然折行不成功 再多的空格都任务是一个空格
$a='
i
love
you
';
echo $a;
echo nl2br($a);
结果1:i love you
结果2:
i
love
you
//表单提交如果你不进行html标签处理那么就会直接显示样式或者js代码直接运行
/*
当你输入
www.jb51.net
一提交就出现是一号大字体
但是你原来是想要
www.jb51.net结果的
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:www.jb51.net
其他查看源码就知道已经被替换了成< >就会在页面原型显示
还有一点要主要 如果不处理有的复制的文章自身有标签样式就会打乱你的页面布局 可能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);
一提交就出现是一号大字体
但是你原来是想要
www.jb51.net结果的
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:www.jb51.net
其他查看源码就知道已经被替换了成< >就会在页面原型显示
还有一点要主要 如果不处理有的复制的文章自身有标签样式就会打乱你的页面布局 可能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);
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入
www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:
www.jb51.net
其他查看源码就知道已经被替换了成< >就会在页面原型显示
还有一点要主要 如果不处理
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);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



An array is a data structure used to store homogeneous elements in sequence. Stored elements are identified by index values or keys. Python has no specific data structure to represent arrays. However, we can use List data structure or Numpy module to handle arrays. In the following article, we will learn how to reverse the elements of an array using python built-in functions. Reversing array elements means changing the order of array elements from front to back. Input-Output Scenarios Now let us look at some input-output scenarios to understand the inversion of array elements. Inputarray:[3,5,1,4,0,2]Outputarray:[2,0,4,1,5,3]The order or arrangement of the input array elements is reversed. Use the built-in

Today I would like to recommend a super easy-to-use built-in function in Python, which is the lambda method. This tutorial will share with you roughly: What is the lambda function? The lambda function filters list elements. The combined lambda function and the map() method use the lambda function. When is it inappropriate to use the lambda method in conjunction with the apply() method? What is a Lambda function? In Python, we often use the lambda keyword to declare an anonymous function. The so-called anonymous function is, in layman’s terms, a function without a name. The specific syntax format is as follows: lambda arguments : expression where it can be connected

As a popular programming language, PHP's widespread use benefits from its flexibility and powerful built-in functions. These built-in functions can both speed up the development process and improve code readability and maintainability. Whether you are a beginner or an experienced developer, you should know and master these essential tools. Some commonly used PHP built-in functions include: String Functions Strings are one of the most common data types in PHP. String functions allow us to process strings, such as finding, replacing, splitting, and formatting

Life is short, learn Python for newbies! I am a rookie brother, and today, we will share 6 magical built-in functions at once. In many computer books, they are also usually introduced as higher-order functions. And in my daily work, I often use them to make code faster and easier to understand. Lambda Function Lambda function is used to create anonymous functions, i.e. functions without a name. It is just an expression, and the function body is much simpler than def. Anonymous functions are used when we need to create a function that performs a single operation and can be written in one line. lambda [arg1 [,arg2,...argn]]: expression lambda's main

Using JavaScript built-in functions for string operations In JavaScript, there are many built-in functions that can be used to handle string operations. These functions can help us change the case of strings, find substrings, replace characters, and more. This article will introduce some commonly used string manipulation functions and give corresponding code examples. The two functions toUpperCase() and toLowerCase() are used to convert strings to uppercase and lowercase respectively. For example: varstr=

As a flexible and powerful programming language, Python has conquered the hearts of programmers, data experts and software craftsmen around the world. Python's massive adoption stems from its rich set of native commands that simplify complex processes, shorten development time, and improve script readability. In this article, we will take an in-depth look at ten key Python native commands that every programmer needs to master for a seamless and efficient coding journey. Using the len() Function The len() command is a simple yet indispensable mechanism for determining the size (i.e., the count of components) of a specified iterable object such as a list, tuple, or string. Example expression="Python"

PHP provides a series of built-in functions for performing various tasks, including: string operations (strcmp, strtoupper, strtolower) array processing (array_push, array_pop, in_array) mathematical operations (round, abs, max) file processing (fopen, fread , fclose)

Built-in functions are predefined functions at the core of Go that make it easy to perform common tasks such as type conversions, string manipulation, and mathematical operations. Specifically, they include: Type conversion functions that allow conversion between different types, such as string, int, and float64. String processing function supports operations such as obtaining length, extracting substrings, and case conversion. Mathematical functions that calculate absolute values, maximum values, minimum values, and rounding. These functions simplify the development process by providing an efficient and standardized way to perform various operations to improve code quality and efficiency.
