4 months ago

Placeholder in string

Posted 4 months ago by movepixels

This might be dumb question, but is it possible to save a string to the database with a variable place holder, then when retrieved you fill the var with the actual value?

I idea is I have about 50+ Sentences / phrases but I need to put place holders in them so its custom to the user.

Example: This would be saved in the database => 'Hello ${name}, we have not seen you since ${date}.'

When pulled from the db, the values are placed into it and returned to the user as a complete string. Hello George, we have not seen you since yesterday.

The point is I know I can simply type it out where needed. But the phrase is based on a stored action in the database so there are 100+ actions each with a phrase to coincide with each.

So in theory a function to get phrase based on action, insert the variables into the placeholders in the string then return full text to user.



Please sign in or create an account to participate in this conversation.