Adding html to a PHP script

Discussion in 'PHP' started by Pea, May 31, 2006.

  1. #1
    Finally found a PHP forum that follows web standards AND isn't bloated.

    I've been trying to add a header bar to a PHP script but it just doesn't like it. Just get errors whever i put the code.

    I'd show you but i'm not allowed..

    If anyone could help it would be great, thanks. Pete
     
    Pea, May 31, 2006 IP
  2. Vewgle

    Vewgle Active Member

    Messages:
    121
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    You want to inject some html in php? If thats what you are asking you have to use the include function. like this

    include 'yourhtml.html';
    Code (markup):
    and the yourhtml.html file obviously holds what you want to inject into the php script.

    or you can use the print function

    like

    print '<pre> this is html </pre>';
    Code (markup):
    Im just learning php so tell me if that what you are talking about.
     
    Vewgle, May 31, 2006 IP
  3. Pea

    Pea Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i havn't tried those strings. I've tried the require one but that didn't work
     
    Pea, May 31, 2006 IP
  4. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Nothing could be simpler. Save the following as test.php, put in your website and try to connect to the page.

    
    <?php
            include "head.html";
            echo '<p>php works here</p>';
    ?>
    
    <p> Click on me <a href="test.php"> click me</a></p>
    </body>
    </html>
    
    Code (markup):
    Create a second file called head.html and put this text in it:

    
    <html>
    <head>
    <title>Imported header</title>
    </head>
    <body>
    
    Code (markup):
     
    clancey, May 31, 2006 IP
  5. DPTony

    DPTony Peon

    Messages:
    329
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you need like a link within the php code say in a loop or something

    echo "<a href=\"link.php\"> YOOYOYO</a>";
     
    DPTony, May 31, 2006 IP
  6. Pea

    Pea Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So much stuff to play with :D. 2.40am..better sleep or something
     
    Pea, May 31, 2006 IP
  7. Pea

    Pea Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This is the error message i'm getting:

    Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux187/p/publicwarehouse.co.uk/user/htdocs/forum/uploads/header.php:5) in /home/fhlinux187/p/publicwarehouse.co.uk/user/htdocs/forum/uploads/index.php on line 1951
     
    Pea, Jun 1, 2006 IP
  8. Pea

    Pea Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ah! I was playing around with positions and worked when i put it over the table not at the very top. Thanks a lot, it's perfect :)
     
    Pea, Jun 1, 2006 IP