title: str_replace inside a foreach within function
body: <p>I am trying to update a block of code with value's sent through a form however I am having trouble updating the whole block of code. The number of inputs change based on the code. For example:</p>
  
  <pre><code>.btn-primary{
    color: @color;
    font-style: none;
    background-color: @background-color;
    transition: all .75s;
    text-transform: uppercase;
    font-weight: @font-weight;
     &amp;:hover{
      background-color: darken(@background-color, 10%);
      font-style: none;
     color: @color; 
    }
  }
  </code></pre>
  
  <p>I am able to sucessfully find the <code>@</code> variables and display the correct number of <code>&lt;input&gt;</code>'s based off the code. The problem I am having is having my foreach loop run through each <code>$_POST</code> value and updating the code. The best result I have been able to get is the first <code>$_POST</code> value but then it cuts off.</p>
  
  <pre><code>function replace_code($code){
   foreach($_POST as $name =&gt; $value){
    return str_replace($name, htmlentities($value), htmlentities($code));
   }
  }
  </code></pre>
  
  <p>In the case of <code>.btn-primary</code> when I fill out my inputs and submit the form the best I can get is the first value to update and that is it. If I were to put <code>#fff</code> in the <code>@color</code> field and other values into <code>@background-color</code> and <code>@font-weight</code> and run my function once submit is set, I get the output of. </p>
  
  <pre><code>.btn-primary{
   color: #fff;
   font-style: none;
   background-color: @background-color;
   transition: all .75s;
   text-transform: uppercase;
   font-weight: @font-weight;
    &amp;:hover{
     background-color: darken(@background-color, 10%);
     font-style: none;
     color: #fff; 
    }
   }
  </code></pre>
  
  <p>Any idea's on how I can get that foreach loop to keep updating the code.</p>