SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict sedna's Avatar
    Join Date
    Jan 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to add <h1> tag into php code

    hey all,

    i am having problems trying to add the <h1> tag to my php code here is the code with out

    PHP Code:
    echo $hackname $result['hackname'] ; 
    basicly what that dose is pull that hacks name from the data base and shows it at the top of the page now when i add my <h1> tags to make that hack look like a title

    PHP Code:
    echo "<h1>" $hackname $result['hackname'"</h1>"
    i get an error is it becuase php dose not allow html tags?, and how would i add that h1 tag to that statement?

  2. #2
    SitePoint Guru
    Join Date
    Oct 2006
    Location
    Queensland, Australia
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are two main methods. I'll demonstrate both.

    #1: The first method is putting the php between html. This is demonstrated below.

    HTML Code:
    <html>
    <head>
    <title>h1 tags</title>
    </head>
    <body>
    <h1><?php echo $hackname = $result['hackname']; ?></h1>
    <p>My little description goes here</p>
    </body>
    </html>
    #2: The second method is to put the html in the php like so...

    HTML Code:
    <html>
    <head>
    <title>h1 tags</title>
    </head>
    <body>
    <?php echo '<h1>' . $hackname = $result['hackname'] . '</h1>'; ?>
    <p>My little description goes here</p>
    </body>
    </html>
    By the way, you can't scrap the whole '$hackname = ' part and just echo $result['hackname']. Defining a variable in an echo statement will work, but doesn't make much sense, especially in your case. Here's the above method without the '$hackname = '.

    HTML Code:
    <html>
    <head>
    <title>h1 tags</title>
    </head>
    <body>
    <?php echo '<h1>' . $result['hackname'] . '</h1>'; ?>
    <p>My little description goes here</p>
    </body>
    </html>

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This makes little sense:
    Quote Originally Posted by sedna View Post
    PHP Code:
    echo $hackname $result['hackname'] ; 
    You'll either do:
    PHP Code:
    $hackname $result['hackname'];
    echo 
    $hackname
    Or:
    PHP Code:
    echo $result['hackname']; 
    This is syntactically illegal, which is why you're getting an error:
    Quote Originally Posted by sedna View Post
    PHP Code:
    echo "<h1>" $hackname $result['hackname'"</h1>"
    You can do this:
    PHP Code:
    $hackname "<h1>" $result['hackname'] . "</h1>";
    echo 
    $hackname
    Or
    PHP Code:
    echo "<h1>" $result['hackname'] . "</h1>"


Bookmarks

Posting Permissions

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