b 整數轉換成二進制
c 整數轉換成對應的ASCII字符
d 整數轉換成十進制
e 整數以科學技術方法顯示
f 轉換成浮點數
o 轉換成八進制
s 整數轉換成字符串
u 整數轉換成無符號整數
x 整數轉換成小寫十六進制
X 整數轉換成大寫十六進制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>
<body>
<?php
$string=15;
printf("%c",$string);
printf("%s",$string);
echo sprintf("%x,%X",$string,$string);
printf("%x,%X",$string,$string);
?>
</body>
</html>
用法和c語音是一樣的 ,就是sprintf之前要加個echo 因爲sprintf只是轉換了格式,並沒有輸出