使用'printf'返回字符串,而不是打印它 [英] using 'printf' to return string, not print it
本文介绍了使用'printf'返回字符串,而不是打印它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这听起来可能很奇怪,但就是这样.
This may sound strange, but here goes.
我喜欢使用这种在 php 中构建字符串的技术
I like using this technique of building a string in php
printf(__('This is %1$s, this is %2$s'), myFunction1(), myFunction2());
显然这会在调用函数时直接打印结果,但我想使用这种技术来构建一个字符串,然后在其他地方使用它.
Obviously this directly prints the results whenever the function is called, but I would like to use this technique to just build a string, and then use it later elsewhere.
这可能吗?
谢谢各位.
推荐答案
使用 sprintf
这样做:
Use sprintf
to do this:
$var = sprintf(__('This is %1$s, this is %2$s'), myFunction1(), myFunction2());
这篇关于使用'printf'返回字符串,而不是打印它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文