Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: PHP in HTML

  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP in HTML

    I'm developing a script for another forum, but I wonder if i can do this:

    <html>
    <body>
    <?php if $variable=0 ?>
    <html code in here>


    I was wondering if that is possible or I need to describe what the variable will have to do first in the php tags, any help?


    Thanks for the help

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Although I suggest you read some beginner tutorials, this is the way you'd do that.

    PHP Code:
    <body>
    <?php
        
    if ($variable == 0) {
            
    ?>
            <p>The variable equals 0.</p>
            <?php
        
    }
    ?>
    </body>
    (The indenting/newlines is not required, just makes it easier to read)

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could you do something like this, (just wondering because I'm a beginner);

    PHP Code:
    <body>
    <?php if ($variable == 0) { ?>
    <style> CSS code here </style>
    <?php ?>
    </body>

    Is this possible?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Dragon Man,

    Isn't that the same thing?

    and also, you could do something like this:

    <body>
    <?php
    $style="<div class='default'> CSS code here </class>";
    if ($variable == 1) { $style="<div class='item1'> Something Else </class>"; }
    if ($variable == 2) { $style="<div class='item2'> Something Else Here</class>"; }
    ?>
    More HTML here<br />
    <?=$style?>
    </body>


    The mix/match of HTML and PHP can be done dozens of ways.
    It's just important to know when to start/stop the PHP and decide
    on echoing with PHP or "including PHP" with HTML.


  •  

    Posting Permissions

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