Printing inside a metatag

Discussion in 'PHP' started by OreoKnight, Mar 11, 2008.

  1. #1
    So what I want to do is similiar to the title but with a different element. As you can see the titles under each article prints correctly on the site; however, I would like the description for each article to be applied in the metatag.... Any ideas on how to do this.... Your help is always appreciated.
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Build Ur Body - <? print $title ?></title>
    <meta name="Description" content="<? print $desc ?>"> <----obviously this doesn't work...... when I check the meta for it is shows up blank....
     
    OreoKnight, Mar 11, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Most likely because the variable isn't set. What output does this give you?
    
    var_dump($desc);
    
    PHP:
    ?
     
    nico_swd, Mar 11, 2008 IP
  3. OreoKnight

    OreoKnight Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Figured it out...I had to make sure to call the query in the top... (not sure if thats the technical term but I'll show ya.)


    $id = explode("/",$_SERVER['PATH_INFO']);
    $id = $id[1];

    $sql = mysql_query("select * from articles where id='$id' limit 1") or die(mysql_error());
    $row = mysql_fetch_assoc($sql);

    $text = $row['text'];
    $title = $row['title'];
    $desc = $row['description'];<----- I added this.....


    // keep empty lines
    function nl2br2($string) {
    $string = str_replace(array("\r\n", "\r", "\n"), "<br />", $string);
    return $string;
    }

    ?>

    After I added that small code, the description was then printing in the metatag. :)
     
    OreoKnight, Mar 11, 2008 IP