Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End preg_replace help?!

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #29625
    nchipping
    Member

    Hi,

    I’m trying to make a templating system that replaces certain patterns (using preg_replace), like {{ variable }} would be turned into <?=$variable?> in the document – does that make sense? So, here’s my code for the document:

    Code:
    include(‘classes/template_classes.php’);
    $template = ”




    {{ title }}

    This is my site, by {{ author }}

    {% foreach news as article %}

    {{ article[‘title’] }}
    {{ article[‘body’] }}

    {% else %}

    There are currently no articles

    {% endforeach %}



    “;
    $tpl = new Template;
    $tpl->replace_variables($template);

    And here is the code I have that should be replacing at LEAST the ‘{{ title }}’ area right now…

    Code:
    final class Template
    {
    public function replace_variables($template)
    {
    $replace = preg_replace(“/{{([.*]+)}}”,”“,$template);

    //echo $tempalte;

    //find anything that exists within {{ * }}
    //find out what * is
    //replace it how it’s supposed to be replaced
    //if it isn’t definded, say so
    echo $template;
    }
    }

    Please help me understand what I’m doing wrong in my regex so I can make this work. I appreciate any help. I have looked at tutorials for days and can’t figure it out!!!

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.