March 2011
Beginner to intermediate
300 pages
7h 23m
English
Since we're talking about sprintf() and its invaluable assistance in formatting translated messages, we should cover the cases where you want to supply it with more than one bit of data. If you've got your multi-lingual "mojo" going on, you will remember that many languages use a different word order than English (for example, noun and then adjective), and this may affect your messages. You can still rely on the sprintf() function, but we need to follow sprintf's rules for argument swapping. If we leave translations out of this for a moment, we can see that argument swapping allows us to specify exactly where the additional arguments get placed into the format string:
$msg_v1 = 'They were %1$s %2$s.'; $msg_v2 = 'The %2$s were ...
Read now
Unlock full access