I am working on a content editor for a website and I would like to allow the admin to put in variables(the currently logged in user's username) into the page content. How would I go about doing this so that it echos the username instead of $username?
I have attempted to use eval but it doesn't seem to work with html tags. I have also tryed to serialize the variable but when I go to echo the unserialized version, it doesn't echo anything. Any ideas?
Saving a Variable in DB
Moderator: General Moderators
Re: Saving a Variable in DB
I have found a workable solution. I use a place holder and then change it just before I display the content using str_replace
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Saving a Variable in DB
Typically you would use embedded tags, much like mail-merge in word processors.
Code: Select all
$str = 'Hello {username}, welcome.';
$output = str_replace('{username}', $username, $str);(#10850)