title: Remove spaces from the beginning and end of a string
body: <p>I am pretty new to regular expressions.
  I need to clean up a search string from spaces at the beginning and the end.
  Example: " search string "
  Result: "search string"</p>
  
  <p>I have a pattern that works as a javascript solution but I cant get it to work on PHP using preg_replace:</p>
  
  <p>Javascript patern that works:</p>
  
  <pre><code>/^[\s]*(.*?)[\s]*$/ig
  </code></pre>
  
  <p>My example:</p>
  
  <pre><code>$string = preg_replace( '/^[\s]*(.*?)[\s]*$/si', '', " search string " );
  print $string; //returns nothing
  </code></pre>
  
  <p>On parse it tells me that g is not recognized so I had to remove it and change the ig to si.</p>