Run code within HTML

Discussion in 'PHP' started by Python, Sep 27, 2007.

  1. #1
    I am developing a script which is quite large therefore it uses templating to manage the way the site looks.

    Basically I have a method within my templating class called render(). When used this simply spits out all of the code to display the site. However within my template files (they are .PHP but the way the templating is set up it doesn't "execute" them) I want to have blocks of PHP code. But obviously when my render() function is echoing out the code, it's displaying the PHP code also.

    So basically lets say I have a variable called $code which contains all of the code (HTML and PHP code) which usually just gets echoed.

    What I want to do is have my script search through this code, find any bits of PHP code and then execute them in their place. Then put the contents of the parsed code back into the $code variable to replace the unparsed version.

    How can I do this?

    Any help much appreciated.

    Thanks
     
    Python, Sep 27, 2007 IP
  2. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Section out your codes in different files (modules) and then use the 'include' to include them back.

    e.g.

    <?include phpcode section1 ?>
    html code1
    <?include phpcode section2 ?>
    html code2
     
    vonvhen, Sep 27, 2007 IP
  3. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #3
    No, I don't think you understand what I'm trying to achieve...


    In my $code variable is this (as just text, so nothing fancy):


    So basically I want to extract the PHP code - execute it - then put the parsed results back in its place. Then put all of it back into the $code variable.
     
    Python, Sep 27, 2007 IP
  4. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #4
    No worries - Ive found a way around it.

    Thanks anyway
     
    Python, Sep 27, 2007 IP
  5. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ? aren't you doing an extra step for the same result.

    anyway, glad you found another way.
     
    vonvhen, Sep 28, 2007 IP