Forum Moderators: not2easy

Message Too Old, No Replies

php & css - Rookie Question

embed php in a css

         

jeffrydell

12:51 am on Apr 27, 2007 (gmt 0)

10+ Year Member



I would like to have a page on my site use a different color scheme from month to month. From an outsider's perspective (no training in .css), it appears this could be approached two ways:

1) I call this the "hard way": Create 12 style sheets, each with the appropriate color scheme for a different month, then link to the proper sheet from within my php script depending on the date.

2) Being a php guy, I call this the "easier & better way" (though I'm afraid this is not possible): Load the appropriate month's color scheme in an array through php, link to one style sheet which calls the colors from the array.

Can php variables be called from a css? If not, is there another (more efficient) way to do this?

Thanks for your time and help from a true 'newbie'.

Jeff

JAB Creations

2:25 am on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not certain about other web servers though Apache does not (by default to my understanding) execute PHP inside of CSS files. You've got to do it the other way.

You would use PHP to detect the month (not sure how) and then echo a variable. Set each stylesheet to a variable.

You could probably even have PHP request a file on your server with the same filename as the month (so when March is detected it would serve march.css).

You'll want to post this idea over in the PHP forums.

- John

jatar_k

2:38 am on Apr 27, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld jeffrydell,

try this thread

Server Side Scripting in CSS Files [webmasterworld.com]

jeffrydell

11:24 am on Apr 27, 2007 (gmt 0)

10+ Year Member



Thanks for the replies - exactly what I was looking for. Amazing that this has been "out there" for over 3 years now and I haven't read about more people doing it.

Even the thought of having .php generate the .css 'on the fly' is intriguing.

Much appreciated! I like this place a LOT already.