SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object-oriented template system with php replacement

    So I'm trying to make an object oriented template system and I found some code that I have modified a bit. All I really need now is to be able to include tags such as {content} <!-- php --> and <!--/php --> But then I wanted to do a str_replace with them and have it replace each with php stuff since php woln't work in the template file. But I knew that wouldn't work because it would only replace as text so I tryed using eval(); but to no avail. Any ideas.

    the things to be replaced are stored in an array such as

    PHP Code:
        array(
            "<!-- PHP -->" => "<?php",
            "
    <!-- /PHP -->" => "?>",
            "{content}" => "<?php include(\"include/levels.php\"); ?>"
        
    )
    then I tyred doing something like this to replace each array varaible with its php counterpart.

    PHP Code:
    function replace_tags($tags = array()) {
            if (
    sizeof($tags) > 0)
            {
                foreach (
    $tags as $tag => $data)
                {
                    
    $data = (file_exists($data)) ? $this->parse($data) : $data;
                    
    $this->page eregi_replace($tag$data$this->page);
                    eval(
    "\$this->page = \"$this->page\";");
                }
            }
            else
            {
                die(
    "No tags designated for replacement.");
            }
        } 

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no need to eval inside the loop. use the loop to replace the template peices to add in your php code. when your all done building your "template with php code" then you can eval it.

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    holy ****... you are a genious... if it works ; )


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •