I'm looking at Webmonkey's PHP and MySql Tutorial, Lesson 2. I think it's a php literal. What does %s
mean? It's inside the print_f()
function in the while loops in at least the first couple of code blocks.
printf("<tr><td>%s %s</td><td>%s</td></tr>n", ...
with printf or sprintf characters preceded by the % sign are placeholders (or tokens). They will be replaced by a variable passed as an argument.
Example:
This will output:
Note: There are more placeholders (%s for string, %d for dec number, etc...)
Order:
The order in which you pass the arguments counts. If you switch $str1 with $str2 as
it will print
You can, however, change the reading order of arguments like this:
which will print the sentence correctly.
Also, keep in mind that PHP is a dynamic language and does not require (or support) explicit type definition. That means it juggles variable types as needed. In sprint it means that if you pass a "string" as argument for a number placeholder (%d), that string will be converted to a number (int, float...) which can have strange results. Here's an example:
this will print
More reading at PHPdocs