PHP, inside of HTML, inside of PHP

ajax , php Canada
  • 14 years ago

    Ok, I have a slight problem that I am wondering if someone could help me out with. Like the title says, I want to include a php file, inside of html code, that is inside of more php code. What I mean by that is that if you look at the code below, you will notice $head = " this is a section of a php file. Now this $head variable is just the header of a template. Anyway, thats not the point. To simplify it, the:

    Blue = PHP script in the php file
    Green = HTML code inside that PHP code
    Red = The php file I want to include but am having trouble doing so

    $head = "
    <html>
    <head>
    <LINK href='../lib/style.css' rel='stylesheet' type='text/css'>
    <title>TITLE</title>
    </head>
    <body>
    <center>

    <div id='wrapper'>

    <div id='topnav'>
    <div class='nav'>











    <? include('../lib/userlogin.php'); ?>
    </div>
    </div>

    <div id='header'>
    <a href='../index.php'><img src='../images/logo.png' border='0' alt='aaa' title='aaa'></a>
    </div>

    <div id='mainnav'>
    <a href='../index.php'><img src='../images/01home.jpg' alt='Home' border='0' height='49' width='191' /></a><a href='../plans.php'><img src='../images/02plans.jpg' alt='Plans' border='0' height='49' width='197' /></a><a href='http://retect.com/forum/'><img src='../images/03forums.jpg' alt='Forums' border='0' height='49' width='201' /></a><a href='#'><img src='../images/04support.jpg' alt='Support' border='0' height='49' width='211' /></a>
    </div>

    <div id='menu'>











    <? include('../admin/lib/nav.php'); ?>
    </div>

    <div id='content'>

    <div class='ads'>
    <p><center>




    <? include('../lib/ads.php'); ?></center></p>
    </div>
    <br>


    ";





    Could anyone please help me out with this problem of how to include a php file, that is inside of html code, that is inside of php script (if its no too confusing :P). Thanks.













  • 14 years ago

    That is indeed an extremely weird way of doing things.... are you sure there's not a better way? Stick out tongue [:P]

    If you want to execute PHP code that's in a string, you'll need to use the eval() function.... look it up in the PHP manual at www.php.net/eval and it will tell you everything you need to know, and more...

    A word of warning though: used carelessly, the eval() function can be extremely dangerous. So read around the subject, do your homework and remember to lock all doors and windows! Big Smile [:D]

  • 14 years ago

    <?
    // The first solution
    $head = "
    <html>
    <head>
    <LINK href='../lib/style.css' rel='stylesheet' type='text/css'>
    <title>TITLE</title>
    </head>
    <body>
    <center>

    <div id='wrapper'>

    <div id='topnav'>
    <div class='nav'>

    ". eval(filegetcontents('../lib/userlogin.php')). "
    </div>
    </div>

    <div id='header'>
    <a href='../index.php'><img src='../images/logo.png' border='0' alt='aaa' title='aaa'></a>
    </div>

    <div id='mainnav'>
    <a href='../index.php'><img src='../images/01home.jpg' alt='Home' border='0' height='49' width='191' /></a><a href='../plans.php'><img src='../images/02plans.jpg' alt='Plans' border='0' height='49' width='197' /></a><a href='http://retect.com/forum/'><img src='../images/03forums.jpg' alt='Forums' border='0' height='49' width='201' /></a><a href='#'><img src='../images/04support.jpg' alt='Support' border='0' height='49' width='211' /></a>
    </div>

    <div id='menu'>
    ". eval(filegetcontents('../admin/lib/nav.php')). "
    </div>

    <div id='content'>

    <div class='ads'>
    <p><center>
    ". eval(filegetcontents('../lib/ads.php')). "</center></p>
    </div>
    <br>
    ";

    ?>

    I can also suggest another one. Parse in JS your HTML and make AJAX-request to controller for every match of <? include(..) ?>, pass to controller including file, eval it within controller and return it into HTML. More about how to handle these AJAX stuff see at http://www.cmsdevelopment.com/en/articles/ajax_grid














































Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programs must be written for people to read, and only incidentally for machines to execute.”