How to use strings with variables in codeigniter's language files? How to use strings with variables in codeigniter's language files? codeigniter codeigniter

How to use strings with variables in codeigniter's language files?


I have the same problem and do it simply by using,

echo sprintf($this->lang->line('somekey'),'XYZ');//load language library before use

Read sprintf()


you can use codeigniter i18n with PHP .sprintf() to achieve what you want. load up the codeigniter non-variable strings (with those format stuff), then pass it on to .sprintf() for formatting and assignment of values. it should replace the %s part.

it's similar to this question. .sprintf() works like .printf(), only that it returns the string rather than printing it.