1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Background image using php

Discussion in 'PHP' started by Jen-, Sep 22, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Hello, I want to insert some images into a background using php.

    I know normally for background images you do this.
    <body style="background: url(http://www.website.com/a.gif);">

    Where does the PHP go, doing it with PHP? Please let me know, thanks very much.
     
    Jen-, Sep 22, 2007 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    
    <?php
    echo "<body style='background: url(http://www.website.com/a.gif);'>";
    ?>
    
    PHP:
    Basically, it is the same as the HTML you are using, although you could save that in an external .php file and use include(),

    BP
     
    blueparukia, Sep 22, 2007 IP
  3. k2pi

    k2pi Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can also insert directely html lines in a php file.
    End the php section with the ?> tag, write yours html line en open an other php section with <?php tag.

    for example :
    <?php
    include "conf.inc.php";
    ?>
    <body style="background: url(http://www.website.com/a.gif);">
    <?
    echo "hello world";
    ?>
     
    k2pi, Sep 22, 2007 IP
  4. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the help.
     
    Jen-, Sep 22, 2007 IP
  5. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #5
    Not one person asked why are you doing this with PHP.

    Why would you? Take a look at how to utilize CSS with your HTML.
     
    KangBroke, Mar 31, 2016 IP
  6. Bitpalace

    Bitpalace Greenhorn

    Messages:
    53
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    13
    #6
    You can simply do

    <body style="background: url(http://www.website.com/<?php echo 'a.gif' ?>);">

    and replace "echo 'a.gif'" with any PHP code of your choice that calculates the right picture. You can also echo a variable that was set previously.
     
    Bitpalace, Mar 31, 2016 IP
Thread Status:
Not open for further replies.