Replacing {placeholders} - only outside certain HTML tags

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stj
Forum Newbie
Posts: 2
Joined: Mon Sep 02, 2002 2:49 am

Replacing {placeholders} - only outside certain HTML tags

Post by stj »

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
Post Reply