Reputation: 12341
How can I use printf to work with parameters regardless of their type? (Something like binding parameters in a prepared statement in PDO).
E.g.:
printf("Hello $s, you have $s new notifications.", $username, $newNotifications);
I tried something like that and didn't work.
Upvotes: 0
Views: 104
Reputation: 157870
echo "Hello $username, you have $newNotifications new notifications.";
note that good syntax highlighter will emphase variables in the string for the even better readability, making this way simply the best.
Upvotes: 0
Reputation: 30555
Look at the man page.
Basically, you're using $s
when you should be using %s
. But you could just use print
or echo
with the string:
print "Hello ".$username.", you have ".$newNotifications." new notifications.";
Upvotes: 1
Reputation: 137398
printf
needs to know how to format the arguments. You could just echo
them instead, using the .
concatenation operator:
echo "Hello " . $username . ", you have " . $newNotifications . " new notifications.";
Upvotes: 0