Question: This is the problem I have: I am making a CSS editor for website administrators, but only for certain styles. What I need is a way to find a word or a phrase in the CSS file (the title of the style), and then change its content. So, in other words, if I have this code:

```
.test_style {
font-size:12px;
color:#ffffff;
}

```

and the administrator chooses the style 

> 
> test\_style
> 
> 
> 

and writes this:

```
font-size:16px;
color:#000000;
font-weight:bold;
margin-top:5px;

```

the PHP script should find the corresponding style, and change the content to this:

```
.test_style {
font-size:16px;
color:#000000;
font-weight:bold;
margin-top:5px;
}

```

Does anyone have any ideas how I could do this?

EDIT: My idea is to let administrators choose a selector from a drop-down menu, write the code in a textarea, and then save the code they write into that specific style in the CSS file.

Answer: 
@Hawili has a great answer, but you can also store the individual rules somewhere else (flat files, couchDB stores, etc). The problem here is interface: do you want them to be able to add their own selectors? Do you want them to pick from a list of selectors that already exist? If they're choosing, why not have them also choose from a list of common declarations, or modify them parametrically? 

The real question you should be asking isn't just how to implement this solution, it's that you should analyze the problem and see if this solution is the correct one. If it really is, you can also use regEx matches to find any code after the selector and modify that with the user's input. But I would recommend you store the discrete data points in some other way easier to modify and then save that output to your css file.
Try to do something like this : 

```
  <form method="POST" action="admin/settings/css-example">

  <textarea id="css-example" name="css-example" rows="10">
  <?php $template_file = "../css-example.css";
  $file_handle = fopen($template_file, "rb");
  echo fread($file_handle, filesize($template_file));
  fclose($file_handle);
  ?>
  </textarea>

  <div class="form-actions">
  <input type="hidden" name="section" value="css-example">
  <input type="submit" name="updatesettings" value="Update">
  </div>
  </form>

```