SED无法使用PHP Shell_exec

So basically i am trying to use sed using user input over a html webinterface to change somne lines in a config file. In this specific case a refresh rate. Done this way:

sed -i '4s/refreshrate.*$/refreshrate: NEWVALUE/g' config.txt

where NEWVALUE is the Number input by the user. I called it "string".

 $string=$_POST["string"];
    $result=shell_exec(' sed -i '4s/refreshrate.*$/refreshrate:'.$string.'/g' config.txt');

Nevertherless sed simply wont work, I am just getting internal server errors. The complete code:

   <?php
$string=$_POST["string"];
$result=shell_exec(' sed -i '4s/refreshrate.*$/refreshrate:'.$string.'/g' config.txt');
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>

<div class="container">

<div class="jumbotron">
  <h1></h1> 

</div>

<div class="row">

<div class="col-md-4">
  <title>Config</title>
</head>

<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Edit Refresh Rate:<input type="text" size="12" maxlength="500" name="string"><br />
<input type="submit" value="submit" name="submit">
</form>
<?
} else {
echo " ".$result."<br />";

//echoerr " ".$result."<br />";
}

I assume it has something to do with the quoatation marks from

'.$string.'

But I am absolutely no expert. So what am I doing wrong here? Or is there a simple alternative to sed in PHP? I would prefer sed with shell_exec, as I have almost no knowledge of PHP.