title: Find all hyperlinks and add another redirect link within a text
body: <p>I want to find all hyperlinks in text and adding a link redirect to every link
  Example text</p>
  
  <pre><code>Hello Visit our website &lt;a href="http://example.com"&gt;Here&lt;/a&gt;
  </code></pre>
  
  <p>The result I want is</p>
  
  <pre><code>Hello Visit our website &lt;a href="https://mywebsite.com?q=http://example.com"&gt;Here&lt;/a&gt;
  </code></pre>
  
  <p>The code I have tried</p>
  
  <pre><code>    $reg_exUrl = "/&lt;a\s[^&gt;]*href=(\\\" ??)([^\\\" &gt;]*?)\\1[^&gt;]*&gt;(.*)&lt;\/a&gt;/siU";
  $text = 'Hello visit our website &lt;a href="https://example.com"&gt;Book&lt;/a&gt;';
  if(preg_match($reg_exUrl, $text, $url)) {
      echo preg_replace($reg_exUrl, '&lt;a href="http://mywebsite.com?q='.$url[0].'"&gt;'.$url[2].'&lt;/a&gt;', $text);
  
  } else {
      echo $text;
  }
  </code></pre>
  
  <p>So the result of my code is</p>
  
  <pre><code>Hello visit our website Book"&gt;https://example.com
  </code></pre>
  
  <p>Which in HTML inspect is</p>
  
  <pre><code>Hello visit our website &lt;a href="http://mywebsite.com?q=&lt;a href="https://example.com"&gt;Book&lt;/a&gt;"&gt;https://example.com&lt;/a&gt;
  </code></pre>