www.webdeveloper.com
Results 1 to 8 of 8

Thread: HTML in PHP

  1. #1
    Join Date
    Nov 2006
    Posts
    172

    HTML in PHP

    Can i write some html code inside php script.
    would it be possible to display a html form using php

    the reason i ask is because i want to have a log in formin an area of the home page that disappears and displays a welcome message when they user logs in along with diffent buttons and features availible to users

  2. #2
    Join Date
    Oct 2004
    Location
    The very depths of programming hell
    Posts
    828
    Yes, just treat html tags the way you'd treat normal text. For example,

    PHP Code:
    <?php

    echo "<form><input><submit></form>";

    ?>
    Would display a perfectly valid HTML form. (Although a bit of a redundant one, I admit.)
    >I suck at this game, can you give me some pointers?

    >> 0x278AB4FF, 0xB5822BB4, 0xAD6E673D.

    > I hate you.


  3. #3
    Join Date
    Nov 2006
    Posts
    172
    could output an entier piecof html like this

    PHP Code:
    echo(        <form method="POST" action="--WEBBOT-SELF--">
                <
    p align="left">Username:<br><input type="text" name="Username" size="18"></p>
                <
    p align="left">Password:<br><input type="text" name="Password" size="18"></p>
                <
    p align="center"><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p>
            </
    form>); 

  4. #4
    Join Date
    Nov 2006
    Posts
    172
    i assume i can if i type it correctly
    PHP Code:
    <?
    echo("<html><body>This is a basic login        <form method="POST" action="--WEBBOT-SELF--">            <p align="left">Username:<br><input type="text" name="Username" size="18"></p><p align="left">Password:<br><input type="text" name="Password" size="18"></p>            <p align="center"><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p>        </form></body></html>");

    ?>
    this works as i'd like it to except for the positioning of it
    but its typed all on the one line
    is that necessary as it'll make it very unreadable

  5. #5
    Join Date
    Oct 2004
    Location
    The very depths of programming hell
    Posts
    828
    It'd need to be as a string, i.e. quoted, but yes. It'd also need to be on one line in the actual document though. New lines can be designated with \n if you want it to look neater in the source, or you can just use an echo statement for each line.
    >I suck at this game, can you give me some pointers?

    >> 0x278AB4FF, 0xB5822BB4, 0xAD6E673D.

    > I hate you.


  6. #6
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    The easiest way - without having to echo yourself to death - would be:
    PHP Code:
    <?php
    // Do whatever you want in PHP
    echo "hello" $name1;
    echo 
    "hello" $name2;
    echo 
    "hello" $name3;
    // Then "break" out of PHP, back to straight HTML
    ?> 
    <form method="POST" action="--WEBBOT-SELF--">
    <p align="left">Username:<br><input type="text" name="Username" size="18"></p>
    <p align="left">Password:<br><input type="text" name="Password" size="18"></p>
    <p align="center"><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p>
    </form>
    <?php
    // If necessary, "break" back in to PHP
    echo "hello" $name4;
    echo 
    "hello" $name5;
    echo 
    "hello" $name6;
    ?>
    <!-- You can also do the same in a single line
    <p align="left">Username:<br>
    <input type="text" name="Username" value="<?php echo $UserName?>size="18">
    </p>

  7. #7
    Join Date
    Oct 2005
    Location
    Gold Coast, Australia
    Posts
    2,115
    I Disagree. The easiest method would be to use the Heredoc syntax:
    PHP Code:
    <?php 

    echo <<<HTML
    hello $name1
    hello 
    $name2
    hello 
    $name3

    <form method="POST" action="--WEBBOT-SELF--"> 
    <p align="left">Username:<br><input type="text" name="Username" size="18"></p> 
    <p align="left">Password:<br><input type="text" name="Password" size="18"></p> 
    <p align="center"><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p> 
    </form> 

    hello 
    $name4
    hello 
    $name5
    hello 
    $name6

    <!-- You can also do the same in a single line -->
    <p align="left">Username:<br> 
    <input type="text" name="Username" value="
    $UserName" size="18"> 
    </p>
    HTML;
    Last edited by pcthug; 03-09-2007 at 07:28 PM.

  8. #8
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    It's a nice feature, I agree, but I prefer to use it only for simple text, as originally intended, as it can make life a little bit more difficult when debugging a script.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles