variables in CSS in PHP question/problems
| From: | Bruce Gilbert | Date: | Tue, 13 Mar 2007 16:12:45 +0000 |
| Subject: | variables in CSS in PHP question/problems | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-250449@lists.php.net to get a copy of this message | ||
I stumbled upon this article http://www.chrisjdavis.org/2005/10/16/php-in-css/
and was trying out variables with PGP, but can't get it to work. I
wanted to have a variable image that changes on refresh, and also set
the body color with PHP/CSS and maybe get that to change on refresh
too.
sp from the tutorial mentioned above I have:
[php]
<?php
/**
*
* create our font class.
*
**/
class font {
/** CONSTRUCTOR
*
* In PHP 4 your constructor has to have the same name as the class
* in PHP 5 it would be thus:
*
* function __construct($args=array()) {
* $this->fields = array'body','image_float');
* foreach ($this->fields as $field) {
* $this->{"$field"} = $args["$field"];
* }
* }
* }
*
**/
function font($args=array()) {
$this->fields = array('body','image_float');
foreach ($this->fields as $field) {
$this->{"$field"} = $args["$field"];
}
}
}
/**
*
* create our color class.
*
**/
class color {
/**
*
* In PHP 4 your constructor has to have the same name as the class, see above.
*
**/
function color($args=array()) {
$this->fields = array('body','image_float');
foreach ($this->fields as $field) {
$this->{"$field"} = $args["$field"];
}
}
}
/**
*
* create and setup our color object
*
**/
$color = new color(array(
body => "#000",
));
/**
*
* And now we write our rotation script
*
**/
function rotater() {
// we start off with the path to your images directory
$path='images';
// srand(time()) will generates the random number we need for our rotater
srand(time());
for ($i=0; $i < 1; $i++) {
// here we are assigning our random number to a variable name so we
can call it later. An important note here, you see we are dividing
rand() by 6, 6 is the number of images you have to work with, so if
you have 10, we would: rand()%10)
$random = (rand()%6);
// so our files in our images folder are named side_image1.gif,
side_image2.gif, side_image3.gif etc. We construct the file name once
we have the random number:
$file = 'image_float';
$image = $path . $file . $random . '.gif';
}
// echo $image here in the function,
}
?>
[/php]
In the XHTML I have:
<div class="image_float"> </div>
and of course a <body> tag.
in my css I have:
div.image_float{
background-image: url(<?php rotater(); ?>) no-repeat;
float:left;
width:75px;
height:75px;
padding:15px;
}
and also
body
{
background-color: <?php echo $color->body; ?>;
}
in my directory, I have a folder called images which is at the root
level with the index file and css, and the images are called
side_image1, side_image2, side_image3 etc.
can anyone see whay this isn't working? Neither the background body
color or the rotating image works.
thanks
--
::Bruce::