SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Code In CSS?

    How do I get PHP code to be executed within my CSS files _AND_ have it work when the page hass XHTML Transitional or XHTML Strict DocTypes?

    Right now I set my stylesheets to be a php file (styles.php) and I have my page's DocType as XHTML Strict. It works fine in IE 6 and Opera 7.5 but it fails in FireFox (no styles are shown). Same thing happens if I change the page to XHTML Transitional. When I remove the DocType, however, it works fine. Any ideas?

    I've also tried adding the following to my .htacess file but this also fails (the php codes doesn't get executed).

    Code:
    AddType application/x-httpd-php .css
    And to mods: I posted this in the CSS forum because this really has more to do with CSS than PHP.
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2003
    Location
    Tulsa, OK
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want .css files to be processed for php before being sent to the browser, you'll have to tell apache to do so (I'm assuming you're using apache.) Depending on your server setup, you may be able to do this through your .htaccess file by adding (or editing if it already exists, this line:

    AddType application/x-httpd-php .php .php3 .phtml .html .css

    This tells apache what files to process for php code.

    EDIT: You might want to leave the .html out of the line above if you don't need html files processed as PHP. Sending .html file through the PHP processor will slightly slow down the speed in speed in serving html files.

  3. #3
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,818
    Mentioned
    158 Post(s)
    Tagged
    4 Thread(s)
    Hi,

    I think you also need to include this line at the top of the css.

    Code:
    <?php Header ("Content-type: text/css");?>
    More info here:

    http://www.karakas-online.de/EN-Book...namic-css.html

    Hope that helps.

    Paul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •