preg_match and preg_replace problem

Well i’ll try and explain my problem in as detail as possible. Here it goes.

I have a [COLOR=red]config.php[/COLOR] file that has variables stored in it as

<?php 
 $host = "localhost";
 $user = "root";
 $pass = "";
 $dbname = "abc";
?>

Now i have another php file with 4 textboxes each for a variable in config.php file.

What i want to do is on click of the save button on this page. I want [COLOR=darkorange]textbox1[/COLOR] value to replace [COLOR=blue]localhost[/COLOR] , [COLOR=darkorange]textbox2[/COLOR] value to replace [COLOR=blue]root[/COLOR] , and on… ,I know i need to use preg_match and preg_replace. but dont know how ?? So a fully explained help with codes would be helpfull so as i could see and learn.

Thanks!!!