i want to include my css/stylesheet via php so that...
so th
why don't you do it the other way around and just include a different css file in your php?
print "<link rel='stylesheet' href='$path_to_css_file'>";
In style.php:
echo file_get_contents('style.css');
This will just output the contents of style.css
.
You can directly include CSS into a HTML file:
<style type="text/css">
<?php include 'stylesheet.php'; ?>
</style>
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" />';
}
?>
Another variation of dynamically changing the page style:
<link rel="stylesheet" href="css/<?php echo $user['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.