Replace Tag with php code

1

Hello, I would like to know if there is a way to do via php what the sublime text does with the snippets. I need to, for example, replace a tag with a preformatted code. Type:

{{repete start}}
  <div class="noticia">Conteúdo</div><br>
{{repete end}}

<!-- isso deverá ser interpretado como abaixo após acessado via web -->
<?php foreach ($noticias as $noticia): ?>
    <?= $noticia['texto'] ?><br>
<?php endforeach ?>

<!-- que no output ficará -->
Conteúdo
Conteúdo
Conteúdo
Conteúdo
Conteúdo
(quantos existirem no banco)

Is it possible to do this using php? My idea is to facilitate the work of integrators who use a panel of administration in php that the company uses. Many thanks.

    
asked by anonymous 19.09.2017 / 23:51

1 answer

1

Example of how to do with PHP: Ex:

{{ variavel }} vira <?php echo $variavel; ?>

PHP code:

preg_replace("/({{([ a-zA-Z]*)}})/gm", "<?php echo \$${2}; ?>", $string);

Of course you will do a fopen to open a file and write the modifications of the view you want. Website to test this regex: link

    
20.09.2017 / 04:01