首頁 >後端開發 >php教程 >powerpoint2012官方下載 PHP print類別函數使用總結

powerpoint2012官方下載 PHP print類別函數使用總結

WBOY
WBOY原創
2016-07-29 08:43:07849瀏覽

複製程式碼 程式碼如下:


/************作者:garcon1986*********/
//print和echo的差別:
//1. echo可以輸入多個字串,而print不能。
print "hello"."world"; //成功
echo "hello"."world"; //成功
//print "hello","world"; //失敗
echo "hello","world"; //成功
//2. echo比print更快。
$stime = microtime(true);
print "hello"."world";
$etime = microtime(true);
$total = $etime - $stime;
echo $total.'
';
//microtime — Return current Unix timestamp with microseconds
$stime2 = microtime(true);
echo "hello"."world";
$ etime2 = microtime(true);
$total2 = $etime2 - $stime2;
echo $total2.'
';
//執行結果:
//helloworld0.00143313407897955
//helloworld0.00018310546875
//看到echo比print更快。
//print_r — Prints human-readable information about a variable 或陣列
$a = "sajfd sfjal sfjalwureoi weu sj we fk io ";
print_r($a); ';
$a = array("b","c","d");
print_r($a);
echo '
';
// var_dump — Dumps information about a variable 或陣列
//var_dump -- 列印變數的相關資訊
$a = "sajfd sfjal sfjalwureoi weu sj we fk io ";
var sfjalwureoi weu sj we fk io ";
var_dump($a); >echo '
';
$a = array("b","c","d");
var_dump($a);
echo '
';
var_dump(array("b","c","d"));
echo '
';
?>
/***********作者:garcon1986********/
//%% - 回傳百分比符號
//%b - 二進位數
//%c - 依照ASCII 值的字元
//%d - 帶符號十進位數
//%e - 可續計數法(如1.5e+3)
//%f - 浮點數(local settings aware)
//%F - 浮點數(not local settings aware)
//%o - 八進制數
//%s - 字串
//%u - 無符號十進制數
//%x - 十六進位數(小寫字母)
//%X - 十六進位數(大寫字母)
//printf()函數輸出格式化的字串
$str = "hello";
$number = 456;
//example1
printf("%s world. Day number %s", $str, $number); //輸出: hello world. Day number 456
print "
";
//example2
printf("%%", $number); //%
print "
";
printf("%b", $number); //111001000
print "
";
printf("%c", $number); //ascii碼
print "
";
printf("%d", $number ); //456
print "
";
printf("%e", $number); //4.560000e+2
print "
";
printf("%f", $number); //456.000000
print "
";
printf("%F", $number); //456.000000
print "
";
printf("%o", $number); //710
print "
";
printf("%s", $number); //456
print "
";
printf("%u", $number); //456
print "
";
printf("%x", $number) ; //1c8
print "
";
printf("%X", $number); //1C8
print "
";
printf("With 2 decimals: %1$.2f
With no decimals: %1$u
",$number);
//With 2 decimals: 456.00
//With no decimals: 456
printf("With 2 decimals: %f
With no decimals: %1$u
",$number);
//With 2 decimals: 456.000000
//With no decimals: 456
//fprintf() 函數把格式化的字串寫到指定的輸出流(例如:檔案或資料庫)。
$file = fopen("text.txt","w");
echo fprintf($file, "fprintf 1: %s world. Day number %u", $str, $number).'
'; //38
echo fprintf($file, "fprintf 2: %f", $number).'
'; //21
echo fprintf($file," fprintf 3: With 2 decimals: %1$.2fnWith no decimals: %1$u",$number).'
'; //56
//vprintf()函數輸出格式化的字串。
//vprintf() 中的 arg 參數位於陣列中。陣列的元素會插入主字串的百分比 (%) 符號。該函數是逐步執行的。在第一個 % 符號中,插入 arg1,在第二個 % 符號處,插入 arg2,依此類推。
vprintf("vprintf: %s world. Day number %u", array($str,$number)); //vprintf: hello world. Day number 456
echo '
';
//sprintf() 函數把格式化的字串寫入變數中。
$txt = sprintf("sprintf: %s world. Day number %u",$str,$number);
echo $txt.'
'; //sprintf: hello world. Day number 456
//vfprintf() Operates as fprintf() but accepts an array of arguments, rather than a variable number of arguments.
echo vfprintf($file, "vfprintfprintf: %u world! ", array($str, $number)).'
'; //37
//vsprintf() Operates as sprintf() but accepts an array of arguments, rather than a variable number of arguments.
$txt = vsprintf("vsprintf: %s world. Day number %u",array($str,$number));
echo $txt.'
'; //vsprintf: hello world. Day number 456
?>

以上就介紹了powerpoint2012官方下載 PHP print類函數使用總結,包括了powerpoint2012官方下載方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn