17

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.

1
  • If you visit the documentation page of a function in the PHP Manual you find always useful tips and related functions, for example sprintf. Commented Sep 29, 2011 at 17:04

1 Answer 1

40

Use sprintf to do this:

$var = sprintf(__('This is %1$s, this is %2$s'), myFunction1(), myFunction2());
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.