Re: [PHP] variables in CSS in PHP question/problems

2007-03-14 Thread Richard Lynch
Surf directly to your CSS URL and see what happens.

There are several possibiliies:
#1.
Your CSS has ?php ... ? in its output, because you have not
convinced your web-server to run your CSS file through PHP to compute
the dynamic result.

You need something like this in .htacces:

File whatever.css
  ForceType application/x-httpd-php
/File


whatever.css should be your CSS filename.

application/x-httpd-php is the default, but your webhost/httpd.conf
could use ANY mime type it felt like using there.  Read your
httpd.conf to figure this out if it's not the usual (above)

Once you get your web-server to pass your CSS through PHP and spit out
the dynamic CSS that you desire...

#2.
Your CSS has what you expect in it, but the browser thinks it's an
HTML document, and shows it as such.

This is because in php.ini your default Content-type is text/html.

But when you spit out your CSS, with the PHP dynamic content to it,
you need this at the very tip-top:

?php
  header(Content-type: text/css);
?

so that the BROWSER knows that you are sending CSS.

Note:
Some browsers may *ignore* the Content-type and assume from the .css
URL that it is CSS.  That's pretty broken, but they are trying to
help the web designers who can't configure their web server to send
the right Content-type for .css files.

#3
Once you have done all that, there is a VERY good chance that your
browser (especially IE) has cached the old .css file...

You may need to hold the control-key and click on the Refresh
button, or hold down SHIFT (or is it ALT?) and control-R for reload
in Mozilla-based, or ...

Actually, if you surf directly to the CSS, and reload that, as in #1
and #2 above, the browser should do the right thing.

But the problem remains that as you change your CSS dynamically, if
the browser is caching the OLD CSS...

So now you may need some no-cache and Last-modified headers as well.

#4
You are on your own to fix the 50-line OOP mess to solve a 1-line
problem... :-)

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variables in CSS in PHP question/problems

2007-03-14 Thread tedd

At 2:15 AM -0500 3/14/07, Richard Lynch wrote:

Surf directly to your CSS URL and see what happens.

There are several possibiliies:
#1.
Your CSS has ?php ... ? in its output, because you have not
convinced your web-server to run your CSS file through PHP to compute
the dynamic result.

You need something like this in .htacces:

File whatever.css
  ForceType application/x-httpd-php
/File

whatever.css should be your CSS filename.



To all:

In addition to what Richard said:

I came into this conversation late, so please forgive me if I'm not 
on track, but if one is trying to use php variables in css, you might 
want to place this at the top of your css files:


?php header('Content-Type: text/css; charset=UTF-8'); ?

and then add this to your .htacces file:

FilesMatch \.(htm|html|css|tpl)$
 SetHandler application/x-httpd-php
/FilesMatch

After that, you can set variables within your css files by ?php 
echo(whatever) ?


hth's

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] variables in CSS in PHP question/problems

2007-03-13 Thread Bruce Gilbert

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_floatnbsp;/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::

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php