How to add html inside php ?

Discussion in 'Programming' started by MeetHere, Oct 18, 2007.

Thread Status:
Not open for further replies.
  1. #1
    I am confused little bit..

    Can anybody guide me "how to add html code between php code ?

    I tried to add html code directly but gives smarty errors..

    Any way to do that ?
     
    MeetHere, Oct 18, 2007 IP
  2. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #2
    <?php
    ?>
    html
    <?php
    ?>

    or

    <?php
    echo '<div id=""></div>';
    ?>
     
    live-cms_com, Oct 18, 2007 IP
    Blesta.Store likes this.
  3. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #3
    OK echo worked. Thanks..

    What does echo means in this php coding ?
     
    MeetHere, Oct 18, 2007 IP
  4. Blinoff

    Blinoff Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It's the same as "print" operator
     
    Blinoff, Oct 18, 2007 IP
  5. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #5
    If I had -
    <?php
    echo 'hi';
    ?>

    it would display -
    hi

    If I had -
    <?php
    $var = 'Daniel';
    echo 'Hello, '.$var.'.';
    ?>

    it would display -
    Hello, Daniel.
     
    live-cms_com, Oct 18, 2007 IP
  6. firesexwater

    firesexwater Peon

    Messages:
    19
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    the easiest way to do it is just basically close your php tag ?> ... and then write your html code then open a new php tag <?php

    <html>
    <head>
    </head>
    <body>
    <?php
    code
    ?>
    text
    <?php
    code2
    ?>
    </body>
    </html>

    (your php tags don't have to be in the body)

    http://www.killersites.com/PHP/find_PHP_host_step2.jsp
     
    firesexwater, Oct 18, 2007 IP
    Blesta.Store likes this.
  7. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #7
    @prise... are you ok? :confused:

    Returning to PHP:

    Using Variables in PHP will be easier if done like this:
    
    <?php
    $var = "Value";
    
    echo "<h3 align=\"center\">Here you will read the Value of the variable:</h3><p align=\"center\">$var</p>";
    
    ?>
    
    Code (markup):
    Using a variable inside ' can be frustrating because you need to use dots to connect it while it will be linear using the " .

    Other example to show the difference:

    
    <?php
    $var_a = "YoGem";
    $var_b = date("d");
    $var_c = date("m");
    $var_d = date("Y");
    
    //Case 1
    echo "<p>$var_a said that today is day $var_b of month $var_c of year $var_d.</p>";
    //Case 2
    echo '<p>'.$var_a.' said that today is day '.$var_b.' of month '.$var_c.' of year '.$var_d.'.';
    ?>
    
    Code (markup):
    Both will return the same thing but... which is the best and easy method? ^_^
     
    YoGem, Aug 29, 2010 IP
  8. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #8
    @YoGem - 'prise' was a spambot (now deleted).

    Go post though, even if it is an old thread. :)
     
    mcfox, Aug 29, 2010 IP
Thread Status:
Not open for further replies.