i want to include my css/stylesheet via php so that...
<link rel="stylesheet" href="http://www.mydomain.com/css/style.php">
so that i can than dynamicly change different stylesheets.... how can i do that
As long as you set your MIME type in style.php to CSS, you should be in business. Add this to the very top:
<?php Header ("Content-type: text/css; charset=utf-8");?>
Another option if you're running on an Apache server is to tell it to check .css files for PHP. Add this to your .htaccess file to do this:
AddType application/x-httpd-php .css
Then you could simply include a regular .css file:
<link rel="stylesheet" href="http://www.mydomain.com/css/style.css">
style.php should allow your original code example to work. I've updated my first example with Gumbo's suggestion of setting the charset at the same time.You can add this php code in your html head section but file should be .php.
For example: index.php
<html>
<head>
<?php
$cssFile = "style.css";
echo "<link rel='stylesheet' href='" . $cssFile . "'>";
?>
</head>
<body>
...
...
</body>
</html>
You can store any css file path in $cssFile variable using different conditions.
The answers seem to be different that they question... If you want to add all CSS files in the CSS map and not have to worry about changing the code whenever a css file name changes or another one is added, use:
<?php
foreach(glob("CSS/*.css") as $css_file)
{
echo '<link rel="stylesheet" href="'.$css_file.'" type="text/css" medial="all" />';
}
?>