E
E
Evgeny Oleinik2015-05-09 16:03:09
PHP
Evgeny Oleinik, 2015-05-09 16:03:09

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

2 answer(s)
I
IceJOKER, 2015-05-09
@HackerZhenya

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

A
Alexey Yakhnenko, 2015-05-09
@ayahnenko

looks like some bullshit.

<?php if ($message): ?>
  <div class="message"><?php echo $message; ?></div>
<?php endif; ?>

this is how you can do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question