NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Dynamic CSS - Syntax highlighting


Joined: 25 Aug 2006
Posts: 18
Location: Netherlands
Reply with quote
Im currently working with a dynamic stylesheet (style.css.php), but I cant get the css syntax highlighting to work with it.

Example:

Code:

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

$style = array(
   'bg_color' => '#000',
   'text_color' => '#fff'
);

?>
html, body {
   margin: 0;
   padding: 0;
   background-color: <? echo $style['bg_color'] ?>;
   color: <? echo $style['text_color'] ?>;
   font: normal 12px/18px tahoma, arial, verdana, sans-serif;
}


Is there some kind of trick to get this to work?
View user's profileFind all posts by SiemaSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Are you using PhpED for Linux or Windows?
Is it 4.6 or an earlier version?
what's particular version&build number?
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 25 Aug 2006
Posts: 18
Location: Netherlands
Reply with quote
dmitri wrote:
Are you using PhpED for Linux or Windows?
Is it 4.6 or an earlier version?
what's particular version&build number?


Im using 4.6 (4621) on windows.
View user's profileFind all posts by SiemaSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
I have good news for you Smile
PHP embedded into CSS and JAVASCRIPT files (by default .css and .js) is supported in PHPED 4.6.1 and it will be released soon.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 25 Aug 2006
Posts: 18
Location: Netherlands
Reply with quote
dmitri wrote:
I have good news for you Smile
PHP embedded into CSS and JAVASCRIPT files (by default .css and .js) is supported in PHPED 4.6.1 and it will be released soon.


Great, thanks alot!
View user's profileFind all posts by SiemaSend private message


Joined: 21 Oct 2004
Posts: 81
Location: UK
Reply with quote
Siema, how do you get the PHP to be parsed in CSS files? Do you give them names like styles.php, or do you have your server set to send .css files to the PHP interpreter? I've often wondering what the most effecient and reliable way of doing this is.
View user's profileFind all posts by QuboidSend private message
Guru master

Joined: 05 Jul 2004
Posts: 659
Location: Belgium
Reply with quote
Quboid as he indicated the file is named style.css.php, so it's being parsed automatically.
You could add the CSS option to the php-extensions in your webserver config as well if you wanted to have a CSS extension,
but i'm not really sure if that is a good idea.
View user's profileFind all posts by BlizzSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
it does not really matters if you store your css files in .css.php or just .php files or add .css to the list of extensions to be processed by php.
Results will be the same.
What really matters is content type. Indeed, your css files must generate Content-Type: text/css header. By default Apache does it for you and Apache's decision is based on the mime-type table lookup with file extension. In case if css file is processed by PHP, it's php will assign Content-Type and by default it is text/html. This is okay for html output, but is not okay for css or js.
To get the proper results, you need
Quote:
<?php
header('Content-Type: text/css');
...
in the beginning of each css file.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 25 Aug 2006
Posts: 18
Location: Netherlands
Reply with quote
Quboid wrote:
Siema, how do you get the PHP to be parsed in CSS files? Do you give them names like styles.php, or do you have your server set to send .css files to the PHP interpreter? I've often wondering what the most effecient and reliable way of doing this is.


By saving them as .php files, like dmitri says.
View user's profileFind all posts by SiemaSend private message
Dynamic CSS - Syntax highlighting
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic