It is currently Fri Oct 18, 2019 1:03 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Using PHP to generate CSS file
PostPosted: Fri Jun 09, 2006 9:10 am 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Hello again. I'm using a PHP script with some included constants for my site to generate the CSS file. I figured that way if I wanted to make a big change in appearance, I could simply alter those few constants and change the whole site. Here's the script:

http://pastebin.com/769432

The problem is that the CSS files it outputs has every tag having every attribute. For example, it creates:
Code:
body{
margin: 5;
background-color: #fffff0;
font-family: arial;
font-color: #d17c80;
color: STYLE_COLOUR3;
font-size: small;
size: medium;
font-weight: bold;
width: 100%;
text-align: justify;
text-decoration: none;
border-width: 1;
border-style: solid;
spacing: 0;
}


font{
margin: 5;
background-color: #fffff0;
font-family: arial;
font-color: #d17c80;
color: STYLE_COLOUR3;
font-size: small;
size: medium;
font-weight: bold;
width: 100%;
text-align: justify;
text-decoration: none;
border-width: 1;
border-style: solid;
spacing: 0;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 9:41 am 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Now it's telling me:

Warning: Invalid argument supplied for foreach() in /home/www/workshop.freefronthost.com/files/css_generator.php on line 204

This is my foreach loop:
Code:
foreach($style as $item=>$value)
{
  fwrite($css, "\r\n".$item."{\r\n");
  foreach($attribute as $item=>$value)
  {
   fwrite($css, $item.": ".$value.";\r\n");
  }
  fwrite($css, "}\r\n\r\n");
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 9:45 am 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Oh, it's because I changed it, got rid of $attribute.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 6:59 pm 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Am I not declaring the array properly or something?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 12:15 pm 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Here is what I have so far. But it's putting ALL attributes into each element, and it tells me there's something wrong with teh foreach loop. I have no idea why either is happening.

Code:
<?php

/* CSS generator. This creates the styles used in the website. */

include("configuration.php");

/***************************************************************/

// Set the various attributes.

// Body

$style["body"]["margin"] = STYLE_MARGINSIZE;

$style["body"]["background-color"] = STYLE_BGCOLOUR;

$style["body"]["font-family"] = STYLE_FONT;

$style["body"]["font-color"] = STYLE_COLOUR1;

// Font

$style["font"]["color"] = STYLE_COLOUR1;

$style["font"]["font-size"] = STYLE_FONT_SIZE;

// Font.small

$style["font.small"]["font-size"] = STYLE_FONT_SIZE_SMALL;

// H1

$style["h1"]["size"] = STYLE_HEADING1_SIZE;

$style["h1"]["color"] = STYLE_BGCOLOUR;

$style["h1"]["background-color"] = STYLE_COLOUR2;

$style["h1"]["font-weight"] = STYLE_HEADING_WEIGHT;

// H2

$style["h2"]["size"] = STYLE_HEADING2_SIZE;

$style["h2"]["color"] = STYLE_BGCOLOUR;

$style["h2"]["background-color"] = STYLE_COLOUR2;

$style["h2"]["font-weight"] = STYLE_HEADING_WEIGHT;

// H3

$style["h3"]["size"] = STYLE_HEADING3_SIZE;

$style["h3"]["color"] = STYLE_BGCOLOUR;

$style["h3"]["background-color"] = STYLE_COLOUR2;

$style["h3"]["font-weight"] = STYLE_HEADING_WEIGHT;

// Hr

$style["hr"]["color"] = STYLE_COLOUR3;

$style["hr"]["width"] = STYLE_WIDTH;

// P

$style["p"]["text-align"] = STYLE_TEXTALIGNMENT;

// A.link

$style["a:link"]["color"] = STYLE_COLOUR3;

$style["a:link"]["font-size"] = STYLE_FONT_SIZE;

$style["a:link"]["text-decoration"] = STYLE_LINK_DECORATION;

$style["a:link"]["font-weight"] = STYLE_LINK_WEIGHT;

// A.visited

$style["a:visited"]["color"] = STYLE_COLOUR3;

$style["a:visited"]["font-size"] = STYLE_FONT_SIZE;

$style["a:visited"]["text-decoration"] = STYLE_LINK_DECORATION;

$style["a:visited"]["font-weight"] = STYLE_LINK_WEIGHT;

// A.active

$style["a:active"]["color"] = STYLE_COLOUR3;

$style["a:active"]["font-size"] = STYLE_FONT_SIZE;

$style["a:active"]["text-decoration"] = STYLE_LINK_DECORATION;

$style["a:active"]["font-weight"] = STYLE_LINK_WEIGHT;

// A.hover

$style["a:hover"]["color"] = STYLE_BGCOLOUR;

$style["a:hover"]["background-color"] = STYLE_COLOUR3;

$style["a:hover"]["font-size"] = STYLE_FONT_SIZE;

$style["a:hover"]["text-decoration"] = "none";

$style["a:hover"]["font-weight"] = STYLE_LINK_WEIGHT;

// A.mini.link

$style["a.mini:link"]["color"] = STYLE_COLOUR3;

$style["a.mini:link"]["font-size"] = STYLE_FONT_SIZE_SMALL;

$style["a.mini:link"]["text-decoration"] = STYLE_LINK_DECORATION;

$style["a.mini:link"]["font-weight"] = STYLE_LINK_WEIGHT;

// A.mini.visited

$style["a.mini:visited"]["color"] = STYLE_COLOUR3;

$style["a.mini:visited"]["font-size"] = STYLE_FONT_SIZE_SMALL;

$style["a.mini:visited"]["text-decoration"] = STYLE_LINK_DECORATION;

$style["a.mini:visited"]["font-weight"] = STYLE_LINK_WEIGHT;

// A.mini.active

$style["a.mini:active"]["color"] = STYLE_COLOUR3;

$style["a.mini:active"]["font-size"] = STYLE_FONT_SIZE_SMALL;

$style["a.mini:active"]["text-decoration"] = STYLE_LINK_DECORATION;

$style["a.mini:active"]["font-weight"] = STYLE_LINK_WEIGHT;

// A.mini.hover

$style["a.mini:hover"]["color"] = STYLE_BGCOLOUR;

$style["a.mini:hover"]["background-color"] = STYLE_COLOUR3;

$style["a.mini:hover"]["font-size"] = STYLE_FONT_SIZE_SMALL;

$style["a.mini:hover"]["text-decoration"] = "none";

$style["a.mini:hover"]["font-weight"] = STYLE_LINK_WEIGHT;

// Table

$style["table"]["width"] = STYLE_WIDTH;

$style["table"]["border-width"] = STYLE_BORDER_WIDTH;

$style["table"]["border-style"] = STYLE_BORDER_STYLE;

$style["table"]["spacing"] = STYLE_SPACING;

$style["table"]["padding"] = STYLE_PADDING;

$style["table"]["background-color"] = STYLE_BGCOLOUR;

// Th

$style["th"]["color"] = STYLE_COLOUR3;

$style["th"]["background-color"] = STYLE_BGCOLOUR;

// .buttons

$style[".buttons"]["color"] = STYLE_COLOUR3;

$style[".buttons"]["background-color"] = STYLE_COLOUR1;

$style[".buttons"]["font-weight"] = STYLE_LINK_WEIGHT;

// Input.focus, Textarea.focus

$style["input:focus, textarea:focus"]["background-color"] = STYLE_COLOUR2;

/***************************************************************/

// Output the styles.

$css = fopen("styles.css", "w");

if(!$css)
{
echo '<br>Could not open CSS for writing.';
}
else
{
foreach($style as $item=>$value)
{
  fwrite($css, "\r\n".$item."{\r\n");
  foreach($attribute as $item=>$value)
  {
   fwrite($css, $item.": ".$value.";\r\n");
  }
  fwrite($css, "}\r\n\r\n");
}
}

fclose($css);

?>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
100WebSpace © 2011