Blogger Information
Blog 46
fans 0
comment 0
visits 34407
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP中,%s与%d是什么意思
上草一方
Original
1504 people have browsed it

在PHP中,经常会遇见%s与%d,本篇将介绍%s与%d是什么意思?
PHP sprintf() 函数用到的参数

printf — 输出格式化字符串

sprintf() 函数把格式化的字符串写入一个变量中。

%% - 返回百分比符号

%b - 二进制数

%c - 依照 ASCII 值的字符

%d - 带符号十进制数

%e - 可续计数法(比如 1.5e+3)

%u - 无符号十进制数

%f - 浮点数(local settings aware)

%F - 浮点数(not local settings aware)

%o - 八进制数

%s - 字符串

%x - 十六进制数(小写字母)

%X - 十六进制数(大写字母)

示例代码如下:

  1. <?php
  2. $colors = ['red','green','blue'];
  3. printf('<pre>%s</pre>',print_r($colors,true));
  4. printf(print_r($colors,true));
  5. ?>

输出效果如下:

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post