[SOLVED]Import CSS To MySQL Table?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

[SOLVED]Import CSS To MySQL Table?

Post by infolock »

I was wondering, has anyone ever tried to develop or seen a tool that will parse a css file, build a table with the layouts, and then dump the values into that table? If not, then I guess I'm gonna have to build one, but was hoping I wouldn't have to go through all that...
Last edited by infolock on Wed Jun 15, 2005 11:18 am, edited 1 time in total.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

n/m, i've almost got my own built now.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

gonna share it :wink:
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

now what do you think? lol. of course! so far all i have is :

Code: Select all

<?php
/*
  #      Author : Jonathon Hibbard
  #        Date : 06/15/05
  # Description : Parses any CSS file passed to it and then posts those values into a mysql table.
*/
  $cssdata = fopen('styletest.css','r'); //open file in read-only mode...
  $line = 1; //Set us to the first line.
  while(!feof($cssdata)) {  //Proceed until we reach the end of the file
    $line_data = fgets($cssdata, 999);  //Get each line individually. this byte value can be raised as needed..
//    print_r($line_data);
//    exit;
    $split_data = preg_split("/[\s]/", $line_data); //Split the line up into arrays so we can use them.
    $line_num = $line++;  //This will keep track of what line we are at all times, so we can use this to build the multi-array
    $split_data = array_filter($split_data);  //Cleanup array
    for($i=0; $i<count($split_data); $i++) { //Now we determine how the array is going to be built based on what data we are seeing.
      $chk_array_val = $split_data[$i]; //Set this to a single variable for simplicity sakes...
      switch($chk_array_val) {
        case '{' :  //Lets us know it's the beginning of a new label/id, so we begin the array construction
          $j = count($split_data); //check to see if we have more than just one label or id name that is to be associated with the elements that will be contained within..
          if($j > 2) {  //this will only ring true when we have more more than just a label/id and a { , telling us this has multiple ids or labels.
            for($ii=0; $ii<$j; $ii++)
            {
              $bob = $split_data[$ii];
              $new_val = explode(',',$bob); //remove commas from the values.
              if($new_val[0] != '{') { //remove the { as it's not needed.
                $double_dragon[$line_num][] = $new_val[0]; //assign it to be processed seperatly, allowing easy element population for each new value.
              }
            }
          }
          else {
            $zelda[$line_num][] = $split_data[0];  //otherwise we just have one id or label, so jus tput it into the singles list
          }
        break;
        case '}' : //this check is needed so that we can tell our script to parse lines from the beginning to the end, and then start over.
          $label_end[] = $line_num;
        break;
      }
    }
  }
# Used for displaying the results of our finds..
  if(count($zelda) != 0 && count($label_end) != 0) {
    echo 'Export data for single unique labels with element data : <br /><br /><pre>';
    print_r($zelda);
    echo '</pre><br /><br />';
    echo 'Export data for double/multiple labels assigned as lists to include identical element data : <br /><br /><pre>';
    if(count($double_dragon) != 0) {
      print_r($double_dragon);
    }
    else {
      echo 'None Recorded!';
    }
    echo '</pre><br /><br />';
    echo 'Export data for end labels : <br /><br /><pre>';
    print_r($label_end);
    echo '</pre><br />';
    exit;
  }
  else {
    echo 'No values were recorded!! >=[';
    exit;
  }
?>
but we're making progress

of course this assumes a strict coding style on the css, but i'm trying to develop it for universal coding styles... we'll see. it only grabs the label values right now, but i'm working on making it more versetile at knowing what type of data it is iterating through... i'll post the finished product when i get done with it
Post Reply