A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

Re-post: Embedding PHP In CSS

This is a re-post from this article.

A few years back, I was looking for a way to embed PHP variables in a CSS file. Anyway, the author did it like this:

<link href="style.php" rel="stylesheet" media="screen" />

And the CSS part…

<?php
/*** set the content type header ***/
header("Content-type: text/css");
 
/** set the paragraph color ***/
$para_color = '#0000ff';
 
/*** set the heading size ***/
$heading_size = '2em';
 
/*** set the heading color ***/
$heading_color = '#c0c0c0';
?>
 
p{
        color: <?php echo $para_color;  ?>;
        font-weight: bold;
        font-size: 1.2em;
        text-align: left;
}       
 
h1{
        color: <?php echo $heading_color; ?>;
        font-size = <?php echo $heading_size; ?>;
        text-align: centre;
}
This entry was posted in General and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>