且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用PHP替换字符串中的变量?

更新时间:2023-02-18 21:22:20

您实际上可以使用 sprintf 函数将返回一个格式化的字符串,并将您的变量放在占位符的位置.
它还为您提供了如何格式化和显示字符串的强大权力.

You can actually use the sprintf function which will return a formatted string and will put your variables on the place of the placeholders.
It also gives you great powers over how you want your string to be formatted and displayed.

$output = sprintf("Here is the result: %s for this date %s", $result, $date);