简体   繁体   English

通过Web界面对CSS文件进行永久更改?

[英]make permanent changes in css file through web interface?

http://www.vector.safwanmanpower.com/ http://www.vector.safwanmanpower.com/

I'm developing a website package,this website package will be given to third party companies so if third party companies want to change background color,font face in css to change this I have created a webpage where all this css property are specified and in textbox they will select background color,font face values and this changes should effect in css file after submitting the changes. 我正在开发一个网站程序包,该网站程序包将提供给第三方公司,因此,如果第三方公司想要更改背景颜色,请在css中更改此字体,我创建了一个网页,其中指定了所有此css属性,并在文本框,他们将选择背景颜色,字体值,并且此更改应在提交更改后在css文件中生效。

My aim behind is this companies can make changes through webpage interface i don't want them to find css code and change the values their to make the work easy. 我背后的目标是这些公司可以通过网页界面进行更改,但我不希望他们找到CSS代码并更改其值以简化工作。

在此处输入图片说明

The idea sounds good, but it will probably be a bit of work, and beyond 1 single answer. 这个想法听上去不错,但可能需要做些工作,而且超出一个答案。 But this is how I would approach it. 但是,这就是我的处理方式。

Have a database storing the current selectors, properties, and values. 有一个数据库,用于存储当前的选择器,属性和值。

Such as : 如 :

selector | property | value
---------+----------+----------
div      | color    | #FFFFFF
div      | float    | left

etc, etc... 等,等等。

On a user submitting a change, do the following things 在提交更改的用户上,执行以下操作

1 - Update the row in the database, for example if I, the user, changes the div to #440044, then update the row so it reads as such: 1-更新数据库中的行,例如,如果我(用户)将div更改为#440044,然后更新该行,则其内容如下:

selector | property | value
---------+----------+----------
div      | color    | #440044
div      | float    | left

2 - Using PHP (or your choice of server side language) pull the contents of the database, organising by selector, using a mySQL query along the lines of: 2-使用PHP(或您选择的服务器端语言)使用mySQL查询通过选择器组织数据库内容,包括:

$query = 'SELECT * FROM css ORDER BY selector';

3 - Loop through these values, grouping them into an array of arrays like this: 3-遍历这些值,将它们分组为如下所示的数组:

$css_array = array();
foreach($rows as $row) {
    if( ! array_key_exists($row['selector'], $css_array)) {
        $css_array[$row['selector']] = array();
    }
    // push each value onto the sub array
    $css_array[$row['selector']][] = $row['property'] . ':' . $row['value'];

}

This will leave you with an array of arrays - each sub array representing an element of the css 这将为您留下一个数组数组-每个子数组代表CSS的一个元素

array(
    'div' => array(
        'color:#440044',
        'float:left'
    ),
    'h1' => array(
        'font-size:16px'
    )
);

4 - Using this array, and the implode method, create a massive string, like: 4-使用此数组和implode方法,创建一个巨大的字符串,例如:

foreach($css_array as $key => $value) {
    $s .= key . '{';
    $s .= implode(';\n', $value);
    $s .= key . '}';
}

5 - This should leave you with a string that looks like a normal css sheet. 5-这应该给您留下一个看起来像普通的CSS表的字符串。 Write this to a file called style.css or similar using the fopen, etc functions in PHP. 使用PHP中的fopen等函数将此文件写入一个名为style.css的文件中。

You will need a little php script, assuming you added the php tag because that's your language of choice. 假设您添加了php标签,您将需要一些php脚本,因为这是您选择的语言。

This script will have to open the appropriate css file, search for the relevant part to change, change it and write the changed file to disk. 该脚本将必须打开相应的CSS文件,搜索要更改的相关部分,对其进行更改,然后将更改后的文件写入磁盘。 You could use a regex Statement to find the relevant class & property of the css file. 您可以使用正则表达式语句查找css文件的相关类和属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM