PHP向浏览器输出内容的4个函数总结,php浏览器输出函数
复制代码 代码如下:
/*
* 0x01:print()语句
* int print(arguments);
* print()语句把传入它的数据输出到浏览器
*/
print("
I love PHP!!!
");print "
I love PHP!!!
";?>
/*
* 0x02:echo()语句,功能和print()函数的功能一样
* 都是将数据输出到浏览器
* echo()函数执行输出的效率比print()函数的效率稍微好一点,因为echo不返回结果
*/
echo "
I love PHP!!!
";$languge="Java";
echo "
I love $languge!!!
";?>
/*
* 0x03:printf()语句
* 如果你想输出由任何静态文本和一个或多个变量中存储的动态信息组成的混合产物,使用printf()函数比较理想
* printf()函数将静态数据和动态数据分为两个部分,其形式如下:
* integer printf(string format [,mixed args]);
*/
printf("
I love %s!!!
","C#");/*
* 上面例子中%s是一个占位符,下面列出常用的占位符
* 类型 描述
* %b 将参数认为是一个整数,显示为二进制数
* %c 将参数认为是一个整数,显示为对应的ASCII字符
* %d 将参数认为是一个整数,显示为有符号的十进制数
* %f 将参数认为是一个浮点数,显示为浮点数
* %o 将参数认为是一个整数,显示为八进制数
* %s 将参数认为是字符串,显示为字符串
* %u 将参数认为是一个整数,显示为无符号整数
* %x 将参数认为是一个整数,显示为小写的16进制数
* %X 将参数认为是一个整数,显示为大写的16进制数
*/
$num=1024;
printf("
%b:%c:%d:%f:%o:%s:%u:%x:%X
",$num,$num,$num,$num,$num,$num,$num,$num,$num);?>
/*
* 0x04:sprintf()语句
* sprintf()函数于printf函数的功能一样,不过它是将输出的值赋给一个字符串,而不是直接输出到浏览器
* 这个函数很有用,比如格式化含有动态输出的字符串,结合上面的占位符,还可以作进制转换,其形式为:
* string sprintf(string format [, mixed args]);
*/
$cost=sprintf("$%.2f",43.2);//$cost=$43.20
?>

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.