title: PHP - Convert space into %20 only in links from text
body: <p>I have a text which contains hyperlinks, some hyperlinks contain spaces and I want to convert them into %20.</p>
  
  <p>For example: </p>
  
  <p>To make hyperlinks <code>&lt;a href="http://www.link-to-my-page.com/page 1.html"&gt;Page 1&lt;/a&gt;</code></p>
  
  <p>If I convert above text using rawurlencode function it returns</p>
  
  <p><code>To%20make%20hyperlinks%20%3Ca%20href%3D%22http%3A%2F%2Fwww.link-to-my-page.com%2Fpage%201.html%22%3EPage%201%3C%2Fa%3E</code></p>
  
  <p>I wrote following RE to convert space into %20 in links only but I am not sure how to apply space (\s)* with preg_replace.</p>
  
  <pre><code>/(http|https|ftp|ftps)(\:\/\/[a-zA-Z0-9\-\.]+)(\s)*\.[a-zA-Z]{2,4}(\/\S*)?/
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks</p>