Table of Contents
www.jb51.net


一提交就出现是一号大字体
但是你原来是想要

www.jb51.net

结果的
所以要处理下
当输入
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入
www.jb51.net

Home Backend Development PHP Tutorial php基础教程 php内置函数实例教程_php基础

php基础教程 php内置函数实例教程_php基础

May 17, 2016 am 09:09 AM
built-in functions

所以爱微网现在讲解先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);

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Python program using built-in function to reverse elements of array Python program using built-in function to reverse elements of array Sep 06, 2023 pm 03:49 PM

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

A brief discussion on the usage of Lambda function in Python A brief discussion on the usage of Lambda function in Python Apr 12, 2023 pm 12:55 PM

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

PHP built-in functions, essential tools PHP built-in functions, essential tools Jun 15, 2023 pm 10:49 PM

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

Six magical built-in functions in Python Six magical built-in functions in Python Apr 13, 2023 am 08:04 AM

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

Use JavaScript's built-in functions to handle string operations Use JavaScript's built-in functions to handle string operations Nov 04, 2023 pm 05:07 PM

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=

10 Python built-in functions you should know 10 Python built-in functions you should know Sep 10, 2023 am 11:45 AM

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&quot

Introduction to PHP built-in functions Introduction to PHP built-in functions Apr 19, 2024 pm 06:39 PM

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 of golang functions Built-in functions of golang functions Apr 21, 2024 am 08:21 AM

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.

See all articles