title: How to use php preg_replace to add base tag to head tag
body: <p>I am outputing some code using a cURL request. In order to change the relative addresses to absolute addresses I want to append a base tag to the head tag.</p>
  
  <p>I was thinking preg_replace can do the trick but i am not too sure about the regex.</p>
  
  <p>i want to append this tag</p>
  
  <pre><code>&lt;base href="url"&gt;
  </code></pre>
  
  <p>What can be the possible regex to append this tag to the $output i get my cURL request.</p>
  
  <p>Here is the code for the cURL request I am using.</p>
  
  <pre><code>$ch = curl_init();
  
  // set a single option...
  // ... or an array of options
  curl_setopt($ch, CURLOPT_URL, $url);
  
      // Set a referer
  
      // User agent
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2");
  
      // Include header in result? (0 = yes, 1 = no)
      curl_setopt($ch, CURLOPT_HEADER, 0);
  
      // Should cURL return or print out the data? (true = return, false = print)
   curl_setopt($ch, CURLOPT_REFERER, $url); 
      // Timeout in seconds
      curl_setopt($ch, CURLOPT_TIMEOUT, 30);
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
  
      // Download the given URL, and return output
      $output = curl_exec($ch);
   $output = str_replace('&lt;/head&gt;','&lt;base href="'.$href.'"&gt;&lt;/head&gt;',$output);
  //$output= preg_replace("/&lt;head&gt;/", "&lt;head&gt;&lt;base href=".$href."&gt;", $output); 
  
   echo $output;
  curl_close($ch);
  </code></pre>