Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is what you are actually looking for,</p> <pre><code>&lt;?php /** PHP, JavaScript and HTML/CSS mixed-code sample */ $string = 'Hello, I am Terry. I like using &lt;a href="http://www.twitter.com"&gt;Twitter&lt;/a&gt;, but I prefer using &lt;a href="http://www.facebook.com"&gt;Facebook&lt;/a&gt;. I like posting blogs on my website at &lt;a href="http://www.mycoolsite.com"&gt;My Cool Site&lt;/a&gt;, and I enjoying playing sports.'; $myurl = "http://www.somepage.com/home?url="; $result = preg_replace('/(&lt;a[^&gt;]*href[\s]*=["|\'])(.*?["|\'])/', "$1$myurl$2", $string); echo $result; ?&gt; </code></pre> <p>You can try that code on phpfiddle.org it's working. Let me know if you need anything change in that.</p> <p><strong>UPDATED CODE:</strong></p> <pre><code>&lt;?php $string = 'Hello, I am Terry. I like using &lt;a href="http://www.twitter.com"&gt;Twitter&lt;/a&gt;, but I prefer using &lt;a href="http://www.facebook.com"&gt;Facebook&lt;/a&gt;. I like posting blogs on my website at &lt;a href="http://www.mycoolsite.com"&gt;My Cool Site&lt;/a&gt;, and I enjoying playing sports.'; $myurl = "http://www.somepage.com/home?url="; preg_match_all('/(&lt;a[^&gt;]*href[\s]*=)["|\'](.*?)["|\']/', $string, $result, PREG_SET_ORDER); for($i=0;$i&lt;count($result);$i++){ $string = str_replace($result[$i][0], $result[$i][1] .'"'. $myurl . urlencode($result[$i][2]) .'"' ,$string); } ?&gt; &lt;!--&lt;textarea&gt;&lt;?php echo $string; ?&gt;&lt;/textarea&gt;--&gt; &lt;?php echo $string; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload