Hi everybody,
doing a global replacing of placeholders (e.g. something like {username} or {date}) with any variable values is easy with the built-in regular expressions.
But I am facing the problem to replace only placeholders in a string variable that are outside certain HTML tags.
For example:
$html='<html><head>{title}</head><body>{title}<br><form action="foo.php">Please specify the placeholder to be used for user names<input type="text" value="{user}"></form></body></html>';
The objective is to replace only the placeholders (in this example it would only be the {title} placeholder, but it could be any) outside the <form> tag.
Does anyone have a good idea how to do this with a regular expressions, perhaps using preg_replace_callback or something?
Thank you in advance for help.
Best regards
Jan Steemann
Replacing {placeholders} - only outside certain HTML tags
Moderator: General Moderators