¶¨ÒåºÍÓ÷¨
sprintf() º¯ÊýÓÃÓڰѸñʽ»¯µÄ×Ö·û´®Ð´ÈëÒ»¸ö±äÁ¿ÖС£
Óï·¨
sprintf(format,arg1,arg2,arg++)
²ÎÊý | ÃèÊö |
---|---|
format | ±ØÐ衣ת»»¸ñʽ¡£ |
arg1 | ±ØÐè¡£¹æ¶¨²åµ½ format ×Ö·û´®ÖеÚÒ»¸ö % ·ûºÅ´¦µÄ²ÎÊý¡£ |
arg2 | ¿ÉÑ¡¡£¹æ¶¨²åµ½ format ×Ö·û´®Öеڶþ¸ö % ·ûºÅ´¦µÄ²ÎÊý¡£ |
arg++ | ¿ÉÑ¡¡£¹æ¶¨²åµ½ format ×Ö·û´®ÖеÚÈý¡¢ËÄµÈµÈ % ·ûºÅ´¦µÄ²ÎÊý¡£ |
˵Ã÷
²ÎÊý format ÊÇת»»µÄ¸ñʽ£¬Ò԰ٷֱȷûºÅ ("%") ¿ªÊ¼µ½×ª»»×Ö·û½áÊø¡£ÏÂÃæµÄ¿ÉÄÜµÄ format Öµ£º
- %% - ·µ»Ø°Ù·Ö±È·ûºÅ
- %b - ¶þ½øÖÆÊý
- %c - ÒÀÕÕ ASCII ÖµµÄ×Ö·û
- %d - ´ø·ûºÅÊ®½øÖÆÊý
- %e - ¿ÉÐø¼ÆÊý·¨£¨±ÈÈç 1.5e+3£©
- %u - ÎÞ·ûºÅÊ®½øÖÆÊý
- %f - ¸¡µãÊý(local settings aware)
- %F - ¸¡µãÊý(not local settings aware)
- %o - °Ë½øÖÆÊý
- %s - ×Ö·û´®
- %x - Ê®Áù½øÖÆÊý£¨Ð¡Ð´×Öĸ£©
- %X - Ê®Áù½øÖÆÊý£¨´óд×Öĸ£©
arg1, arg2, ++ µÈ²ÎÊý½«²åÈëµ½Ö÷×Ö·û´®ÖеİٷֺŠ(%) ·ûºÅ´¦¡£¸Ãº¯ÊýÊÇÖð²½Ö´Ðеġ£ÔÚµÚÒ»¸ö % ·ûºÅÖУ¬²åÈë arg1£¬ÔÚµÚ¶þ¸ö % ·ûºÅ´¦£¬²åÈë arg2£¬ÒÀ´ËÀàÍÆ
ÌáʾºÍ×¢ÊÍ
×¢ÊÍ£ºÈç¹û % ·ûºÅ¶àÓÚ arg ²ÎÊý£¬ÔòÄú±ØÐëʹÓÃռλ·û¡£Õ¼Î»·û²åµ½ % ·ûºÅºóÃ棬ÓÉÊý×ÖºÍ "\$" ×é³É¡£Çë²Î¼ûÀý×Ó 3¡£
Àý×Ó
Àý×Ó 1
<?php $str = "Hello"; $number = 123; $txt = sprintf("%s world. Day number %u",$str,$number); echo $txt; ?>
Êä³ö£ºHello world. Day number 123
Àý×Ó 2
<?php
$number = 123;
$txt = sprintf("%f",$number);
echo $txt;
?>
¡¡
Êä³ö£º
123.000000
Àý×Ó 3
<?php
$number = 123;
$txt = sprintf("With 2 decimals: %1\$.2f<br />With no decimals: %1\$u",$number);
echo $txt;
?>
Êä³ö£º
With 2 decimals: 123.00
With no decimals: 123
Àý×Ó4
<?php
$ctype_primary = strtolower('application');
$ctype_secondary = strtolower('pdf');
$mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
echo $mimetype;
?>
Êä³ö£º
application/pdf
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ