How do I set a variable in a PHP page, pass it to a CSS file and assign it to a single CSS attribute?

I'm not familiar with the engine you mentioned (Serindipity), but this should be pretty straightforward, as long as you are allowed to create and edit your own Php-scripts (which really shouldn't matter as long the engine isn't dependent on the name of the style-sheet ): Change the file-ending of the style-sheet to php and the webserver will recognize it as a php-script. Set the mime-type to text/css like @Brighty wrote header('Content-type: text/css') and the user will never know the difference (except, of course, the file-ending being php ) If the style-sheet having a file-ending of php is a problem, you can always use . Htaccess and some clever regex to make the user believe they are seeing a css Edit: Also, if you have access to configure what file/s will be recognized as php-scripts, you can set your server to also recognize css as a php-file (which, as far as I know wouldn't be a problem, since php will just toss any plain text encountered out to the user).

I'm not familiar with the engine you mentioned (Serindipity), but this should be pretty straightforward, as long as you are allowed to create and edit your own Php-scripts (which really shouldn't matter as long the engine isn't dependent on the name of the style-sheet): Change the file-ending of the style-sheet to . Php and the webserver will recognize it as a php-script. Set the mime-type to text/css like @Brighty wrote header('Content-type: text/css'); and the user will never know the difference (except, of course, the file-ending being .

Php). If the style-sheet having a file-ending of . Php is a problem, you can always use .

Htaccess and some clever regex to make the user believe they are seeing a .css. Edit: Also, if you have access to configure what file/s will be recognized as php-scripts, you can set your server to also recognize . Css as a php-file (which, as far as I know wouldn't be a problem, since php will just toss any plain text encountered out to the user).

Hmm.. interesting. And will all of the CSS instructions in the file still read the same, just as if it were still a . Css file?

– James Kotak Nov 8 at 10:32 Of course. Do this as a proof of concept: Create a php-file, write the php start- and end-tags (write some expression between these if you want), and below the end-tags (or above the start-tags) write some text. – Marcus Hansson Nov 8 at 10:35 The text (plus the output of the expression, if you wrote any) will be tossed to the user as plain text (which will be rendered as usual by the user, in the case of e.g. Html).

– Marcus Hansson Nov 8 at 10:37 1 @JamesKotak Now, I know how frustrating it is to get an answer like that, but please understand, we are doing this on our spare time, and however much I would like to give you an in-depth tutorial, it is simply not possible, or even appropriate, on this site. So, before you ask any more questions, try going to the tutorial I linked, click here, it's actually very helpful and not a little easy for the beginner :) – Marcus Hansson Nov 8 at 11:57 1 I have been looking though the page you linked too earlier and am now learning PHP! Thanks again.

Also, @Dunhamzzz: I apologize; I realize what you were saying now. I misunderstood your point. I wasn't taking into account the link Marcus gave me.

My bad. Thanks to you both. – James Kotak Nov 8 at 12:27.

Just make sure your file is a . Php file and you can just use PHP in it like so: body { background: } div { color: } Obviously this is quite flexible! Here's a link I found extending the method even more.

Thanks for the reply. It's a CSS file. I am kind of stuck in that regard.

I have to be able to dynamically change the value of the background-color property to the variable, and only if the variable = "transparent". – James Kotak Nov 8 at 10:09.

You can't set any variable in the css file, jquery or javascript is the best option to play with your css file. Or you will do with inline css.

– James Kotak Nov 8 at 10:10 @JamesKotak as you said above you want to change the background-color property only if the variable is "transparent" right, then assign a variable in php and if the variable is true set the background-color into inline css with a property '! Important', hope you understand – jogesh_p Nov 8 at 10:18 Yes, I do - thanks. Unfortunately, the CSS file will be called later on by one of the many complex files that make up the Serindipity blog application, which will override any inline instructions.

– James Kotak Nov 8 at 10:20.

You may be able to achieve this by mixing css and php code in a single file with a php extension, and setting the mime type of the file to 'text/css'. Header('Content-type: text/css'); I have done a similar thing in ColdFusion but never in php so I can't guarantee this will work.

Thanks. This won't work for me, as I am bound by the structure of the Serindipity application. Changing the core structure would require basically rewriting portions of the most complex part of the code, and unfortunately I am a total n00b.

– James Kotak Nov 8 at 10:16 Unfortunately that's the only way I know to get conditional logic into a css file. It looks like changing the background colour with javascript is your best bet. – Brighty Nov 8 at 10:24 ...and there's no way to run a script within a CSS file, right?

– James Kotak Nov 8 at 10:29 Thanks Brighty... Marcus Hasson is expounding on this concept a littel more for me. Much appreciated! – James Kotak Nov 8 at 10:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions