簡體   English   中英

sprintf非常簡單的問題

[英]php - sprintf very simple question

我只是想知道是否忽略sprintf的論點是否會引起任何問題。

我不記得是肯定的,但我想我的網站,如果我忽略它error'd出來的參數中的一個,但我想它在不同的服務器上,它不是所有的PHP錯誤通知張貼任何問題開啟。

只想仔細檢查!

例:

sprintf('This is an example %s','test'); // outputs "This is an example test"
sprintf('This is an example','test'); // outputs "This is an example"

如果傳遞的參數太少,將會出錯,但是可以傳遞太多的參數。 就像其他PHP一樣,如果您傳遞過多的參數,它們將被忽略。

$ php -r "echo sprintf('foo %s');"
PHP Warning:  printf(): Too few arguments in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. printf() Command line code:1

Warning: printf(): Too few arguments in Command line code on line 1

Call Stack:
    0.0005     314336   1. {main}() Command line code:0
    0.0006     314408   2. printf() Command line code:1

$ php -r "printf('foo %s', 'foo', 'bar');"
foo foo

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM