search
Homephp教程php手册php sprintf()函数让你的sql操作更安全

$bookSQL=sprintf("UPDATE book SET pass=%s WHERE id=%d",
                              GetSQLValueString($_POST['list'], "text"),
                              GetSQLValueString($_GET['id'],"int"));

GetSQLValueString 这个函数,可以换成别的函数

但在sql语句这里用上sprintf()这个函数的话!就相对安全多了,比如id那里我们可以用上%d

或是有很多sql操作的时候,用上这个


$Result = $db->query($bookSQL) or die(mysql_error());


下面加上sprintf这个函数的说明:

引用
sprintf

将字符串格式化。

语法: string sprintf(string format, mixed [args]...);

返回值: 字符串

函数种类: 资料处理

内容说明

本函数用来将字符串格式化。参数 format 是转换的格式,以百分比符号 % 开始到转换字符为止。而在转换的格式间依序包括了

填空字符。0 的话表示空格填 0;空格是默认值,表示空格就放着。
对齐方式。默认值为向右对齐,负号表向左对齐。
字段宽度。为最小宽度。
精确度。指在小数点后的浮点数位数。
类型,见下表 % 印出百分比符号,不转换。
b 整数转成二进位。
c 整数转成对应的 ASCII 字符。
d 整数转成十进位。
f 倍精确度数字转成浮点数。
o 整数转成八进位。
s 整数转成字符串。
x 整数转成小写十六进位。
X 整数转成大写十六进位。 

Statement
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor