Note that there are some explanatory texts on larger screens.

plurals
  1. POPreg-replace - replace all URLs except a domain and its subdomains
    text
    copied!<p>I've a Glype proxy and I want not parse external URLs. All URLs on the page are automatically converted to: <em>http://proxy.com/browse.php?u=[URL HERE]</em>. Example: If I visit The Pirate Bay on my proxy, then I want not to parse the following URLs:</p> <pre><code>ByteLove.com (Not to: http://proxy.com/browse.php?u=http://bytelove.com&amp;b=0) BayFiles.com (Not to: http://proxy.com/browse.php?u=http://bayfiles.com&amp;b=0) BayIMG.com (Not to: http://proxy.com/browse.php?u=http://bayimg.com&amp;b=0) PasteBay.com (Not to: http://proxy.com/browse.php?u=http://pastebay.com&amp;b=0) Ipredator.com (Not to: http://proxy.com/browse.php?u=https://ipredator.se&amp;b=0) etc. </code></pre> <p>Of course I want to keep the internal URLs, so:</p> <pre><code>thepiratebay.se/browse (To: http://proxy.com/browse.php?u=http://thepiratebay.se/browse&amp;b=0) thepiratebay.se/top (To: http://proxy.com/browse.php?u=http://thepiratebay.se/top&amp;b=0) thepiratebay.se/recent (To: http://proxy.com/browse.php?u=http://thepiratebay.se/recent&amp;b=0) etc. </code></pre> <p>Is there a preg_replace to replace all URL's except thepiratebay.se and there subdomains (as in the example)? An other function is also welcome. (Such as domdocument, querypath, substr or strpos. Not str_replace because then I should define all URLs)</p> <p>I've found something, but I'm not familiar with preg_replace:</p> <pre><code>$exclude = '.thepiratebay.se'; $pattern = '(https?\:\/\/.*?\..*?)(?=\s|$)'; $message= preg_replace("~(($exclude)?($pattern))~i", '$2&lt;a href="$4" target="_blank"&gt;$5&lt;/a&gt;$6', $message); </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