title: Trim only the first and last occurrence of a character in a string (PHP)
body: <p>This is something I could hack together, but I wondered if anybody had a clean solution to my problem. Something that I throw together wont necessarily be very concise or speedy!</p>
  
  <p>I have a string like this <code>///hello/world///</code>. I need to strip only the first and last slash, none of the others, so that I get a string like this <code>//hello/world//</code>.</p>
  
  <p>PHP's <code>trim</code> isn't quite right right: performing <code>trim($string, '/')</code> will return <code>hello/world</code>.</p>
  
  <p>One thing to note is that the string won't necessarily have any slashes at the beginning or end. Here are a few examples of what I would like to happen to different strings:</p>
  
  <pre><code>///hello/world/// &gt; //hello/world//
  /hello/world/// &gt; hello/world//
  hello/world/ &gt; hello/world
  </code></pre>
  
  <p>Thanks in advance for any help!</p>