HTML Code in PHP

Discussion in 'QnA (read only)' started by gursimran_2006, Oct 18, 2006.

Thread Status:
Not open for further replies.
  1. gursimran_2006

    gursimran_2006 New Member

    Joined:
    Sep 26, 2006
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    In ur Dreams
    How 2 add HTML Code In PHP Webpage
     
  2. mediator

    mediator New Member

    Joined:
    Mar 18, 2005
    Messages:
    2,491
    Likes Received:
    16
    Trophy Points:
    0
    Location:
    In ur Evil Mind!
    Thats easy! U have 2 options
    Let me give u an example with <a href...> thing!

    1. : Parting the Php block
    Code:
    <?php
    {
    //code...php block initiated
    ?>
    [b]<a href="mediator_is_great.htm">meds</a>[/b]
    <?php
    //code php block completed
    }
    ?>
    
    2. : In one go!
    Code:
    <?php
    $link="mediator_is_great.html";
    $name="meds";
    echo "[b]<a href=\"$link\">$name</a>[/b]";
    ?>
    
    Like wise to mark something bold we have
    Code:
    <?php
    echo "<b>mediator is cool</b>";
    ?>
    
    Ur Problem Solved!
     
    Last edited: Oct 18, 2006
  3. Stick

    Stick New Member

    Joined:
    Aug 14, 2006
    Messages:
    570
    Likes Received:
    0
    Trophy Points:
    0
    Just use it after any php code end (IMO), google further
     
  4. kalpik

    kalpik In Pursuit of "Happyness"

    Joined:
    May 18, 2005
    Messages:
    3,002
    Likes Received:
    15
    Trophy Points:
    0
    Location:
    New Delhi
    Mediator has given the correct solution, so no need to google!
     
  5. ahref

    ahref eWebGuru

    Joined:
    Mar 11, 2006
    Messages:
    427
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    Dehradun
    Although mediator has explained clearly. Let me add my two cents
    Server will treat everything outside <?php ?> tags as html.
    If you want to add any html tag in php script then use eithter echo or print command like
    <?php
    print "<h1>Hello World</h1>";
    ?>
     
  6. tuxfan

    tuxfan New Member

    Joined:
    Feb 4, 2004
    Messages:
    2,653
    Likes Received:
    9
    Trophy Points:
    0
    Location:
    Mumbai
    My further 1 cent in addition to ahref's 2 cents ;)

    Its not the server that treats PHP, its the PHP interpreter that does the job!! Here's the over-simplified sequence.
    1. A browser sends a request for a file to the server.
    2. If its .php file, Apache calls in PHP interpreter for help and hands over the file to it.
    3. PHP interpreter goes thru the file and processes everything thats within <?php and ?> tags. However, it doesn't do anything to the code thats outside those tags.
    4. Apache once again takes over the output give by the interpreter and hands it over to the browser which is dumb enough to understand only HTML and Javascript.
    5. If the browser is IE, it will render even a W3 standard compliant page erroneously. If the browser is not IE, it is more likely that the page is rendered correctly :D
    I would also like to point out that PHP can be used anywhere on the page whether it be <head> or <title> or whatever!! For example, based on certain criterion, it can even me made to select a differnt external CSS files or change the title of the page. Here's a small simple example.

    PHP:
    <html>
      <head>
        <title>
          <?php
            $myid 
    $_GET["identity"];
            if (
    $myid == "one")
              print(
    "This is the my favourite page tite");
             else
              print(
    "This is the default page title");
          
    ?>
        </title>
      </head>
      <body>
      </body>
    </html>
    So start thinking a little differently. You can use break-away from static code anywhere with just the <?php and ?> tags. All that you need is .php extension to the file.
     
    Last edited: Oct 19, 2006
  7. [xubz]

    [xubz] "The Cake is a Lie!!"

    Joined:
    Oct 14, 2006
    Messages:
    471
    Likes Received:
    2
    Trophy Points:
    0
    Guys, its better if you use PHP BBCode Tag..

    PHP:
    <html>
      <body>
        <b>
        <?php
           $a
    =1;
           
    $b=2;
           if(
    $a==$b) {
              echo 
    "Bull5hit!";
           } else {
              die(
    "Yay!");
           }
         
    ?>
         </b>
      </body>
    </html>
     
  8. tuxfan

    tuxfan New Member

    Joined:
    Feb 4, 2004
    Messages:
    2,653
    Likes Received:
    9
    Trophy Points:
    0
    Location:
    Mumbai
    At first, I didn't understand what you are saying! But then found out that you are right. You are talking about the php tag for posting in the forum. The tag makes the PHP code more readable on the forum :) and its nothing to do with the php tag in HTML pages.
     
Thread Status:
Not open for further replies.

Share This Page