title: PHP: replace relative urls to absolute urls in a textarea
body: <p>I would like to replace relative URLs to absolute URLs in a textarea. So something like this:</p>
  
  <pre><code>/somefolder/somefile 
  </code></pre>
  
  <p>Is replaced to:</p>
  
  <pre><code>http://www.mysite123.com/somefolder/somefile
  </code></pre>
  
  <p>I have this replace function to do the job:</p>
  
  <pre><code>$replaceStrs = array('href=/', "href='/", 'href="/');
  $datdescription = str_ireplace($replaceStrs, 'href="http://www.' . $domain . "/", $datdescription);
  </code></pre>
  
  <ol>
  <li>The problem is that it needs a <code>/</code> in the start of the value and therefore a URL like <code>href=somefolder/somefile</code> would not be replaced. </li>
  <li>I also would like it to work if there are spaces before or <code>/</code> and after the <code>=</code> in the <code>href</code> part.</li>
  </ol>
  
  <p>Point 1 is most important. Can you help to improve this?</p>
  
  <p>I have seen PHP examples that replaces relative URLs to absolute URLs <a href="http://nashruddin.com/PHP_Script_for_Converting_Relative_to_Absolute_URL" rel="nofollow">like this one</a>.</p>
  
  <p>But the requirement is that the relative URL is known <code>/</code> found but in my case I have not managed this part (I am working with replacing all URLs in a textarea).</p>