Answer the question
In order to leave comments, you need to log in
Templates and placeholders. Why does not it work?
There is some page. It has placeholders like {message}.
When the user gets to the main page, a message about successful registration will appear at this place. But there is a problem - when there is no message, the placeholder is visible! I can't get it off the page. Make an array and loop through each time to remove not unnecessary - not an option, because. there are a lot of them and it is not convenient to edit this array every time.
I replace it with content like this:
$html = str_replace("{placeholder}", $content, $html);
The catch is that the code doesn't know the name of the placeholder, so the loop won't help.
Answer the question
In order to leave comments, you need to log in
This logic is not clear, why create unnecessary problems for yourself, but in this case I think preg_replace() will help .
That is, first you replace, and after preg_replace() you "pick up" the remaining placeholders
ps I hope I understood you correctly
looks like some bullshit.
<?php if ($message): ?>
<div class="message"><?php echo $message; ?></div>
<?php endif; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question