I need a PHP function which reads a string. This string contains some keywords which are between %, for example %KEYWORD%. This expression should be replace through the constant KEYWORD. Check before if this constant exists, when not, do not replace. Moreover the string contains links with following syntax: [FILENAME_XXX]Some Text[/FILENAME_XXX] In This case you have to create a link (FILENAME_XXX is placeholder for a constant with an url) with link text between this link tags [XXX] [/XXX]. Check before if this constant exists, when not, do not replace. The first part should solved first, then the second, because I want that dynamic part like [FILENAME_ACCOUNT]%ANY_CONSTANT%[/FILENAME_ACCOUNT] works as well. It should also works, when on tag appears several times, as in side the example (FILENAME_ACCOUNT tag is use several times)
The needed code should be in one function:
// constants are defined somewhere
define('FILENAME_ACCOUNT', '[url removed, login to view]');
define('FILENAME_LOGOUT', '[url removed, login to view]');
// your work is inside this function onaly
// example string
$str = "<strong>Hi, %USER_NAME%.</strong> Click [FILENAME_ACCOUNT]here[/FILENAME_ACCOUNT] for visiting your [FILENAME_ACCOUNT]Account[/FILENAME_ACCOUNT]. (You are not %USER_NAME%? Click [FILENAME_LOGOUT]here[/FILENAME_LOGOUT].)";
$new_str = your_function($str);
<strong>Hi, Phil.</strong> Click <a href="[url removed, login to view]">here< / a > for visiting your <a href="[url removed, login to view]">Account< / a >. (You are not Phil? Click <a href="[url removed, login to view]">here< / a >.)
please notice: "< / a >" should have no " ", rentacoder does not display it, when I write it correct.
Edit: I changed the exmaple sentence from german to english, that it is easer for you to understand. In my php script, I can define translations, and Inside these translations, I like to show constants as text and a possibility to show dynamic links.