title: Is there an easy way to replace an url parameter in a referer in Symfony 2?
body: <p>I am trying to update a parameter in my referer url:</p>
  
  <pre><code>$referer = $request-&gt;headers-&gt;get('referer');
  </code></pre>
  
  <p>For example, <code>$referer</code> is an url whith two parameter: </p>
  
  <pre><code>string(96) "http://&lt;my_url&gt;/web/app_dev.php/urlpart/?param1=value1&amp;param2=value2"
  </code></pre>
  
  <p>I'd like to easyly replace <code>param1=value1</code> by <code>param1=updatedvalue1</code> for example with another one. </p>
  
  <p>I know we can do this with <code>twig</code> with the current request url:</p>
  
  <pre><code>{{ path(app.request.attributes.get('_route'),
     app.request.query.all|merge({'sort': 'address'})) }}
  </code></pre>
  
  <p>Is it possible to do the same thing in a Symfony 2 controller to update the referer?</p>
  
  <p>I have found a solution with <code>preg_replace</code> function in <code>PHP</code>, I hope there is a better way to do it seems ugly, I am trying to find a better solution, any help will be apprecied!</p>
  
  <pre><code>$referer = preg_replace('/([?&amp;])(param1)=\w+(&amp;|$)/', '', $referer);
  $referer = preg_replace('/(param2)=\w+(&amp;|$)/', '', $referer);
  </code></pre>
  
  <p>Thank you for your help !</p>