can i use meta tag within php tags?

Discussion in 'PHP' started by whiteblue1942, May 16, 2008.

  1. #1
    i have a homepage that is all php and i wanted to know if i can throw in the meta tag in between the php tags or will it mess it up? liek this...

    <?php
    <meta tag>
    ?>


    can someone tell me if this would be ok
     
    whiteblue1942, May 16, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    <?php
    	echo '<meta tag';
    ?>
    Code (markup):
    is that what you mean?
     
    crath, May 16, 2008 IP
  3. whiteblue1942

    whiteblue1942 Peon

    Messages:
    573
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    then it will output the meta tag ont he screen instead of interepreting it wont it?
     
    whiteblue1942, May 16, 2008 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    nope. the browser reads anything php puts out as plain old html
     
    crath, May 16, 2008 IP
  5. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if you have your var inside your config file you can use is like this

    config.php

    $desc= "your site description here";

    then in your php script you can use this

    <META NAME="Description" CONTENT="<?php echo $desc ?>">

    is this what you meen
     
    cornetofreak, May 17, 2008 IP
  6. xd2

    xd2 Peon

    Messages:
    694
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you don't need it in the php tags then don't put it in them. Either do what cornetofreak suggested or just close php tags and do html. I even do it for IF statements like:
    <?php
    if($something) { ?>
    html without the need for \'s everywhere
    <?php } ?>
    Code (markup):
     
    xd2, May 17, 2008 IP
  7. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #7
    that makes for ugly looking code.

    He said his whole site is already all php, so just

    echo "meta tag here";

    and your good
     
    crath, May 18, 2008 IP
  8. neil patrick harris

    neil patrick harris Peon

    Messages:
    288
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You just want to put in keywords right?
    This page is php just right click and look at the source of this page.

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="generator" content="vBulletin 3.6.8" />


    <meta name="keywords" content="search engine marketing" />
    <meta name="description" content="Search Engine Optimization and Marketing forum." />
     
    neil patrick harris, May 18, 2008 IP
  9. xd2

    xd2 Peon

    Messages:
    694
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    How is that ugly?

    All your doing is adding <? ?> when you want to put some html in. That is less charicters then putting in echo""; and it also saves the need to use \'s everywhere you plan to use quotes.

    Still, it's down to you how you want to do it :)
     
    xd2, May 18, 2008 IP
  10. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #10
    When echoing html, you usually use ' ' instead of " " because then you dont have to \" the " 's
     
    crath, May 18, 2008 IP
  11. xd2

    xd2 Peon

    Messages:
    694
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #11
    When using html I write it how I write html. I may need to put a ' in the title of an image so would still need \'s The same goes for if I wanted to ad any javascript.

    At the end of the day, it is each to their own. I am not saying my way is the right way but I offered a suggestion. I know my way works so i am not going to tell people another way am I?
     
    xd2, May 18, 2008 IP