Using the Case statement for Meta Descriptions

Discussion in 'PHP' started by aaron_nimocks, Jun 8, 2007.

  1. #1
    I have a 50 page site that uses PHP. Im looking at making meta descriptions for each page. Now the easiest way I can think of is using cases.

    Now Im looking at just doing cases based on the URL. So the depending on the URL I can enter a varialble for the meta description.

    Heres the basic idea but it dont work.

    
    <?php
    switch ($_SERVER["PHP_SELF"]) 
    {
    case "/page1":
        $description = "page 1 description";
        break;
    case "/page2":
        $description = "page 2 description";
        break;
    case "/page3":
        $description = "page 3 description";
        break;
    }
    ?> 
    PHP:
    Could anyone help me complete my idea. Im a little confused on what to use for the switch.

    Thanks
     
    aaron_nimocks, Jun 8, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    $_SERVER["PHP_SELF"] referrers to the filename, and not the request URI.

    it should look more of less like:
    
    <?php
    switch (basename($_SERVER["PHP_SELF"]))
    {
    case "page1.php":
        $description = "page 1 description";
        break;
    case "page2.php":
        $description = "page 2 description";
        break;
    case "page3.php":
        $description = "page 3 description";
        break;
    }
    ?>
    
    PHP:
    Just echo $_SERVER["PHP_SELF"] and you'll see what you get, and what you need as case.
     
    nico_swd, Jun 8, 2007 IP
  3. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #3
    Thanks will give it a shot real quick.
     
    aaron_nimocks, Jun 8, 2007 IP