Separating HTML And PHP Code

A Member? Please Login  
type your username and password to login
Date: October 14, 2008, 09:38 PM
249956 members and 148650 Topics
Latest Member: diertiatazy
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Webmasters (Moderators: SAM MILLA, uspry1)  |  Separating HTML And PHP Code
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Separating HTML And PHP Code  (Read 584 views)
rock2 (m)
Separating HTML And PHP Code
« on: January 13, 2007, 01:50 PM »

This is for our web developers.  How do you seperate your code(PHP) from the HTML design.  I mean making them independent of each other.  Thanks.
my2cents (m)
Re: Html And Code ?
« #1 on: January 13, 2007, 02:35 PM »

I separate my code (not limited to PHP) from HTML in one of 2 ways:

1) use of includes (e.g. require_once()):

<?php require_once('header.php'); ?>
        <table>
            <tr>
                <td>
                    Hello Nairaland!!
                 </td>
             </tr>
        </table>
<?php require_once('footer.php'); ?>

2) beginning my code tabbed over once from the line and my HTML tabbed over 2ce from the line.  In other words, take PHP for example:

<?php
    $uri = $_SERVER['REQUEST_URI'];    //to obtain what comes after www.nairaland.com in address bar above
   
    if(strchr($uri, "topic=35738") {        //does the uri contain the string, "topic=35738"?
?>
        <table>
            <tr>
                <td>
                    Hello Nairaland!!
                 </td>
             </tr>
        </table>
<?php
    } else {
?>
        <table>
            <tr>
                <td>
                    Hello Nigeriaworld!!
                 </td>
             </tr>
        </table>
<?php
    }//if
?>

Of course, for #2, I could hv printed out the strings without using tables.  I just wanted to illustrate indentation  Tongue

I hope this helps
 Web Design  World Summit on the Information Society (WSIS): Hope for Nigeria?  How Can I Design A Website?  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Job Talk Jobs/Vacancies (2) Career Talk Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.