使用PHP在文件夹中搜索CSS并更改css值

I'm new to php and need some help.

I have a text box that a user can type in an html color code (ex:#373737). Once they hit the submit button I want find all color codes matching #379BB9 and replacing them with the new color code they typed in the text box. I want to change this entry on all the css files in a folder. What i'm looking for is the php code to make this work. I've found bits and pieces of code but I could make it work. I only put the code here that relates to the button. Thanks for any help you can give.

Here's the original color code: #379BB9

p {
    background-color:#373737;
    border:1px solid #373737;
    padding-top:5px;
    padding-bottom:5px;
    padding-left:10px;
    padding-right:10px;
    color:#379BB9;
    width:60px;
    cursor:pointer;
    -moz-border-radius:3px;
    border-radius:3px;
    text-transform:uppercase;
} 

.message {
    background-color:#4f4f4f;
    border:1px solid #373737;
    width:98.5%;
    text-align:center;
    margin-bottom:30px;
    -moz-border-radius:3px;
    border-radius:3px;
    text-transform:none;
    color:#379BB9;  
}

.steps {
    text-transform:none;
    color:#379BB9;
}

div.notinstalled {
        color:#f20723;
}

div.installed {
        color:#2cb517;
}

#content a:link, #content a:visited {
    color:#379BB9;
    font-weight:bold;
    text-decoration:none;
}
<h2>My example.php</h2>
<?php
Need php here........
?>
<label id="steps">Here you can set the theme color.</label>
<br>
<Form name="default1" method="POST" action="example.php">
<label for="defaultcolor">Theme Color: </label><input style="color:#ffffff" type="text" id="defaultcolor" name="defaultcolor" value="Add color code here">
<br>
<input type="submit" name="setcolor" value="Set Theme Color">
</form>

</div>

Here the code:-

if(isset($_REQUEST['setcolor'])){
$arr=glob("css\*.css"); //your css file's path
$colorcode=$_POST['defaultcolor'];    
foreach($arr as $key=>$val){
$str=file_get_contents($val);
//$str=preg_replace('/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/',$colorcode, $str); //for replace all colour code
$str=str_replace("#379BB9", $colorcode,$str ); // for replace only desired colour code
file_put_contents($val, $str);
}
}