0

What does the $GLOBALS['s'] variable contain? It looks like an empty array, but what would it normally hold?

I've encountered it in a tutorial: The WordPress Theme: Single Post, Post Attachment, & 404 Templates, it mentions a long string that gets passed to a printf function call.

The string looks something like this:

//START OF STRING

$entry_utility = <<<LONGSTR
This entry was posted in %1{$s}%2{$s}.
Bookmark the <a href="%3{$s}" title="Permalink to %4{$s}" rel="bookmark">permalink</a>.
Follow any comments here with the
<a href="%5{$s}" title="Comments RSS to %4{$s}" rel="alternate" type="application/rss+xml">RSS feed for this post</a>.
LONGSTR;

//END OF STRING

NOTE: I've wrapped the long string from the tutorial inside a HEREDOC string instead, it was too hard to follow on the single line.

I've wrapped the $s variables in curly-brackets in case heredocs couldn't interpret them correctly.

1 Answer 1

2

It's not a global variable; in fact it's not a variable at all. It's just placeholder within the sprintf() function. Take a look at the sprintf PHP function documentation.

In the example you cite, the author is using the 'argument swapping' placeholder syntax: %n$t where %n is the placeholder number that corresponds to the argument order (eg: %1, %2 etc) and $t is the type indicator, where 't' is one of 's', 'd', 'f' etc (eg: $s, $d etc). Put them together and you get %1$s %2$d etc.

1
  • Thanks! Good thing to note too, because I was treating it as a variable, it didn't function properly for the sprintf / printf method. Once I've wrapped the string back into single-quotes (which would prevent the variables from converting to strings, I think), it worked fine! Oct 28, 2011 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.