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
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
In style.php:
echo file_get_contents('style.css');
This will just output the contents of style.css
.
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">
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.
Or you may specify link better:
<link rel="stylesheet" type="text/css" href="http://www.mydomain.com/css/style.php">
But isn't good to have preprocessor for styles, rather use anything like this:
$style;
switch($page_type){
case "home":$style="/home.css";break;
case "about":$style="/about.css";break;
}
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$style."\" />";
If user want to style pages more dynamically then do it with javascript, why use server resources and user resources keep unused?
You can directly include CSS into a HTML file:
<style type="text/css">
<?php include 'stylesheet.php'; ?>
</style>
Another variation of dynamically changing the page style:
<link rel="stylesheet" href="css/<?php echo $user['style']; ?>.css">