treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Proper Way / Good practice in Coding php and html/css

  • hi there,

    when a programmer saw my code in php and css.. he said that i should separate my codes..
    example:

    function fNavi() {
    $list = a class='navi' href='#'>HOME</a>;
    $list .= ]<a class='navi' href='#'>CONTACT</a>;
    return $list;
    }
    echo fNavi();

    and i dont understand what he was trying to tell me..he said it's a wrong practice embedding the html/css tags in my php code.

    i really wanted to learn and improve my code in a professional way , good practice.

    can somebody help me.... thanks
  • he might have meant to use the php tags



    <?php
    function fNavi() {
    $list = ?> a class='navi' href='#'>HOME</a>;
    <?php $list .= ] ?> <a class='navi' href='#'>CONTACT</a>;
    <?php return $list;
    }
    echo fNavi();
    ?>
  • Create your nav as normal html
    <ul class=\"nav\">
    <li><a href=\"#\">HOME</a></li>
    <li><a href=\"#\">CONTACT</a></li>
    </ul>

    and save it as nav.php.inc

    Then in your html page, where ever you want it to appear
    <?php include ('nav.php.inc'); ?>

    EDIT:
    Obviously you would save your html page with the .php extension. eg. index.php