Topic: using PHP to extract CSS variables (Read 854 times)
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« on: Jul 11, 2007, 10:36:35 AM »
is there anyway with PHP to extract variables from a CSS stylesheet? hypothetically, like so:
say we have some stylesheet, style.css, here is the content:
Code:
.tableClass { background-color: #ffffff; }
and then we have a php file that calls upon this stylesheet in the header, but somehow extras that background-color value from the stylesheet? is this possible? or what I am asking for is too much of PHP
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« Reply #4 on: Jul 12, 2007, 09:58:59 AM »
i suppose that is because of file_get_contents..hmm i will have to play around with it some and see how I can get this css file something I can work with in PHP
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« Reply #5 on: Jul 12, 2007, 05:02:22 PM »
another idea, maybe a bit noobish, but tell me if this is a better way..
just create a new DB table, and run this script with file_get_contents, and load the necessary values once at the first script execution, to grab the values needed, then store them in the DB. when needed, just call them from the DB as usual. if style file is changed, re-run the file_get script..
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« Reply #8 on: Jul 12, 2007, 08:57:49 PM »
well basically, this script should get this value from the CSS file because the themes are separate from the actual CMS that I am modifying for a client, and each theme and CSS value for this class we are looking up is unique. so, he wants the table cells when hovered to change color (like some forum themes for phpBB and etc). simple to do, with HTML, but it should match each theme used, even if the theme is changed, so the value for the colors will also change. in this case, we need php to get these values on-the-fly. i would rather not use a DB to store the data, i'd like to to be on each page view, but with file_get_contents you say this creates too much overhead
maybe you can use inline styles plus dyn. values instead
you mean like adding the styles directly to the PHP page? no this wont work, its not a CMS im developing, this is a CMS that already exists.. the theme has each style file, i have a solution now that works but it requires file_get_contents to load the CSS code into a string
this is the stylesheet we are referring to, styles.css, and as you see by the used definition THEME, it varies depending on site settings and user preference. therefore, the color for the following has to be dynamic based on the theme in question:
as you expect, the variables above are just added to table cell tags and this makes the background switch back and forth based on the themes colors in the CSS File, what i intended to do, was this:
<?php //function.strBetween: Returns a string found between 2 strings, in a string function strBetween($s1,$s2,$s){
//function.tblClass: reads the CSS stylesheet and extracts the appropriate class values $cssFile = file_get_contents(THEME."styles.css"); function tblClass($tbl){