Orionsbelter Posted May 10, 2008 Share Posted May 10, 2008 If so How because i really need too Quote Link to comment https://forums.phpfreaks.com/topic/105074-can-i-add-php-in-a-css/ Share on other sites More sharing options...
rhyboo Posted May 11, 2008 Share Posted May 11, 2008 You can include your .css doc with the "include();" function like so; <?php include("style.css"); ?> or you can directly insert your css content into a .php file; <?php //php code goes here //start your css h2 { color: black; font-weight: bold; font-size: 1.2em; text-align: left; } // end of css CSS; ?> Hope that helps, not sure on how to directly insert PHP into a .css document but this way is probably more preferred by Developers. Quote Link to comment https://forums.phpfreaks.com/topic/105074-can-i-add-php-in-a-css/#findComment-538012 Share on other sites More sharing options...
dbrimlow Posted May 12, 2008 Share Posted May 12, 2008 You can't insert php into a css document. Think about it. PHP only works with a .php extension. Once you convert a .css file to a .php file, it is no longer a .css file. A solution similar to Rhyboo's solution is best ... generate your entire inline php on the fly in the head tag. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>php in head</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php echo" <style type=\"text/css\"> body { color: #000; background-color:#fff; font-size: small; margin:0; } etc., etc., <style>"; ?> <head> <body> Quote Link to comment https://forums.phpfreaks.com/topic/105074-can-i-add-php-in-a-css/#findComment-538605 Share on other sites More sharing options...
haku Posted May 12, 2008 Share Posted May 12, 2008 There are actually a couple ways to include php in css files. Method 1) Include your CSS, and change your filename from whatever.css to whatever.php. Then link to the file like this: <link rel="stylesheet" type="text/css" href="whatever.php" /> Method 2) Use your .htaccess file to have .css files processed as php files. In this way you don't have to change any file names or links, but you will take a hit in that apparently your css sheets don't cache, which basically takes the functionality out of a css sheet, and as such this method probably shouldn't be used. Method 3) The third method is discussed here, although the article in question is actually about gzipping css sheets, rather than about using php in css. But in order to use this method, your css sheets all need to be php, so following this method will do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/105074-can-i-add-php-in-a-css/#findComment-538812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.