如何使用 printf 处理参数而不管其类型如何? (类似于PDO中预准备语句中的绑定参数)。
E.g:
printf("Hello $s, you have $s new notifications.", $username, $newNotifications);
我尝试了类似的东西但没有用。
答案 0 :(得分:1)
查看man page。
基本上,当您使用$s
时,您正在使用%s
。但您可以使用print
或echo
使用字符串:
print "Hello ".$username.", you have ".$newNotifications." new notifications.";
答案 1 :(得分:0)
printf
需要知道如何格式化参数。您可以使用echo
连接运算符.
代替 echo "Hello " . $username . ", you have " . $newNotifications . " new notifications.";
。
{{1}}
答案 2 :(得分:0)
echo "Hello $username, you have $newNotifications new notifications.";
请注意,良好的语法高亮显示器将强调字符串中的变量,以获得更好的可读性,这使得这种方式更加出色。