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

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

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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.

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
