Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: Easy title/keyword tags

  1. #16
    Join Date
    Apr 2012
    Quote Originally Posted by NogDog View Post
    I might do something like this (or I might not ):
    PHP Code:
     * Get HTML text for title element plus keywords and description meta tags
     * @return string
     * @param string $pageName Top-level key in $data array
    function getHtmlHead($pageName="default")
    $data = array(
    "default" => array(
    "title" => "Default Title",
    "keywords" => array(
    "description" => "This is a sample description."
    "index" => array(
    "title" => "Home",
    "keywords" => array(
    "description" => "Welcome to the home page."
    "schedule" => array(
    "title" => "Schedule",
    "keywords" => array(
    "description" => "This is the schedule page."
       if( ! 
    array_key_exists($pageName$data)) {
    $pageName "default";
    error_log("Invalid pageName '$pageName' in ".__FUNCTION__."()");
    $template = <<<EOD
    <meta name='keywords' content='%s' />
    <meta name='description' content='%s' />


    htmlspecialcahrs(implode(', '$data[$pageName]['keywords'])),
    PHP Code:
    require_once 'path/to/the/above/file.php';
    <div>Main content here...</div>
    Hi NogDog,

    A belated question/reply to this thread but I wanted to ask you something about the solution you provided.

    Basically I am using what some people describe as an ungly case/switch method within my index.php gile to switch the title tags etc etc.

    Your method looks nice and I wondered if there are any performance implications using a nested array?

  2. #17
    Join Date
    Dec 2011
    I think you will find the performance neglible.
    a switch/case & if/else will create code like
        move AX,VariableA
        compare AX, ConstantA
        jumpnotequal Compare2
        move ax, Data1
        jump done
        compare AX, ConstantB
        jumpnotequal, Compare3
        move ax, Data2
        jump done
    while an array system will reuse the comparison routine
       move AX, VariableA
       MOV DX, ArrayConstant
       move IX, 0
       Compare [DX+IX], AX
       jumpequal done
       Increment IX
       jump Compare1
    Although the use of the array shortens the amount of code produced, it does have the slight overhead of the math to calculate the position of the next element. The code snippets are pseudo code, and very simplified, but it's just to give an idea of what is produced by the interpreter/compiler.

    For myself, I prefer using an array system. Because it keeps code more compact. When you been around for awhile and see if/else...switch/case statements hitting 30-50 blocks. and trying to fix/update the code becomes a chore.

    My rule of thumb is never to use more than 3-5 if/else...switch/case statements. At this point consider using an array system.

    New coders often find using arrays difficult so postpone learning them.

    Anyways good luck on yer coding

  3. #18
    Join Date
    Aug 2004
    Another good rule of thumb is to code for maintainability first, and worry about performance only if and when you find that you have to. (More often than not, your main performance bottlenecks will be the database, not your PHP code -- unless it's really, really awful ). That's not to say you shouldn't think about code efficiency at all, but I'd rather worry about saving hours of debugging versus microseconds of performance.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #19
    Join Date
    Apr 2012
    To all,
    Great work. You all have given very valuable information
    Thank You

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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