PHP printf()º¯Êý¸ñʽ»¯Ê¹ÓÃÏê½â
printf()º¯ÊýÓŵãÔÚÓÚ¿ÉÒÔ¸ñʽ»¯Êä³ö!
¸ñʽÈçÏÂ:%['padding_character][-][width][.precision]type
ËùÓеÄת»»ËµÃ÷¶¼ÊÇÒÔ%¿ªÊ¼,Èç¹ûÏë´òÓ¡Ò»¸ö%·ûºÅ,±ØÐëÓÃ%%.
²ÎÊý'padding_characterÊÇ¿ÉÑ¡.Ëü½«±»ÓÃÀ´Ìî³ä±äÁ¿Ö±ÖÁËùÖ¸¶¨µÄ¿í¶È.¸Ã²ÎÊýµÄ×÷ÓþÍÔÚ±äÁ¿Ç°ÃæÌî³ä.ĬÈϵÄÌî³ä×Ö·ûÊÇÒ»¸ö¿Õ¸ñ,Èç¹ûÖ¸¶¨0»òÕß¿Õ¸ñ,¾Í²»ÐèÒª ' µ¥ÒýºÅ×÷Ϊǰ׺,ÆäËû×Ö·û¾Í±ØÐëÖ¸¶¨ ' ×÷Ϊǰ׺.
²ÎÊý - ÊÇ¿ÉÑ¡.ËüÖ¸×ó¶ÔÆë,ĬÈÏÊÇÓÒ¶ÔÆë.
²ÎÊýwidthÊÇÖ¸±»Ìæ»»µÄ±äÁ¿µÄ³¤¶È.
²ÎÊýprecision±íʾÒÔСÊýµã¿ªÊ¼.ËüÖ¸Ã÷СÊýµãºóÒªÏÔʾµÄλÊý.
²ÎÊýtype ÊÇÀàÐÍÂë,Ç뿴ϱí:
ÀàÐÍ | º¬Òå
b | ½âÊÍΪÕûÊý²¢×÷Ϊ¶þ½øÖÆÊä³ö.
c | ½âÊÍΪÕûÊý²¢×÷Ϊ×Ö·û±íʾÊä³ö(ASCIIÂë).
d | ½âÊÍΪÕûÊý²¢×÷ΪÕûÊýÊä³ö.
f | ½âÊÍΪ˫¾«¶È²¢×÷Ϊ¸¡µãÊýÊä³ö.
o | ½âÊÍΪÕûÊý²¢×÷Ϊ°Ë½øÖÆÊýÊä³ö.
s | ½âÊÍΪ×Ö·û´®²¢Îª×Ö·û´®Êä³ö.
u | ½âÊÍΪÕûÊý²¢×÷Ϊ·ÇÖ¸¶¨Ð¡ÊýÊä³ö.
x | ½âÊÍΪÕûÊý²¢×÷Ϊ´øÓÐСд×Öĸa-fµÄÊ®Áù½øÖÆÊýÊä³ö
X | ½âÊÍΪÕûÊý²¢×÷Ϊ´øÓдóд×ÖĸA-FµÄÊ®Áù½øÖÆÊýÊä³ö
ÑÝʾ:
$test=array(
'%d'=>100,
'%s'=>'hello world!',
'%b'=>8,
'%o'=>8,
'%x'=>10,
'%X'=>10,
'%c'=>97,
'%.2f'=>1234.343,
'%u'=>1234.343,
'%\'02d'=>'1',//Ìî³ä
);
foreach($test as $key=>$value){
printf($key,$value);
echo '<br/>';
}
²âÊÔ½á¹û:
100hello world!
1000
10
a
A
a
1234.34
1234
01
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ