shane
shane

Reputation: 862

using 'printf' to return string, not print it

This may sound strange, but here goes.

I like using this technique of building a string in php

printf(__('This is %1$s, this is %2$s'), myFunction1(), myFunction2());

Obviously this directly prints the results whenever the function is called, but I would like to use this technique to just build a string, and then use it later elsewhere.

Is this possible?

Thanks guys.

Upvotes: 17

Views: 8512

Answers (1)

Jason
Jason

Reputation: 89102

Use sprintf to do this:

$var = sprintf(__('This is %1$s, this is %2$s'), myFunction1(), myFunction2());

Upvotes: 40

Related Questions