Forum Moderators: not2easy

Message Too Old, No Replies

css with php

using php variables in css

         

gymsmoke

10:21 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



I found an article which i believe was published on one of the forums here, but cannot find it. It was about using php variables in css. I tried this simple version (below), but for some reason couldn't make it work. Any input is greatly appreciated.

(mytest.php)
<!doctype html public "~//w3c//dtd html 4.0 transitional//en">
<html><head><title>php-css-test<title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body><a href="linkme.php">Link Me Here</a>
</body></html>
------------------
(mystyle.css)
<?php header("content-type: text/css");?>

<?php $linkcolor = "00FF00"; $hovercolor="0000FF";?>

a {
color:#<?php echo $linkcolor;?>;
}

a hover {
color:#<?php echo $hovercolor;?>;
}

encyclo

11:47 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the forums gymsmoke.

This may be the thread you are looking for:

[webmasterworld.com...]

One potential problem: are your .css files parsed for PHP? If not, you will need either to do so, or you can simply name your stylesheet file with a PHP extension:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>php-css-test<title>
<link rel="stylesheet" type="text/css" [b]href="mystyle.php"[/b]>
</head>
<body><a href="linkme.php">Link Me Here</a>
</body></html>

PS. your listed doctype was incorrect - I would suggest the one I gave above ;)

gymsmoke

9:24 am on Oct 3, 2005 (gmt 0)

10+ Year Member



encyclo~
Thanks for the reply (and the welcome!). That article was the one I found prior to registering here. I will try and reply there, but since that thread appears to be over 2 years old, I'm afraid I may not find any answers...
I did follow your suggestions, changed the doc type, and also made the link ref to a php file. No changes.
I did note the .htaccess addition, and made sure that it was there. I'm scratching my head at this point as to how something so seemingly simple can be so elusive...

If you can provide any further input, or maybe shake the tree of the person who posted the original solution, I'd be grateful.

gymsmoke

9:33 am on Oct 3, 2005 (gmt 0)

10+ Year Member



encyclo~
a little trial and error...
it does work! (the .htaccess wasn't right, but it is now)...

Thanks a lot for your help...

Now I can read back through that thread and see what else I can glean from it

gymsmoke

10:09 am on Oct 3, 2005 (gmt 0)

10+ Year Member



encyclo~
and i can now pass parameters to the css to conditionally set attributes for css classes...
I've been reading through some other articles here and on a couple of the forums... I can't believe that the people at school and work didn't tell me about this site before! Hopefully, I'll have something of my own to contribute before long...

Thanks again for the response.