Like
$args = ( 'var1' => 'abc', 'var2' => 'def', ); $text = sprintf('first var is: %1$s, second one is: %2$s', $args);
Basically the $args
variable is dynamic, I don't know if it will have any entries or how many.
The text too, I don't know if it will require variables to be replaced in it, or how many.
How can I make a function like this, that somehow extracts the elements and replaces them in the text if stuff like %s
%d
, %1$s
etc is present?
You probably want vsprintf()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With