Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use this regex:</p> <pre><code>#(\s|^)((?:https?://)?\w+(?:\.\w+)+(?&lt;=\.(net|org|edu|com))(?:/[^\s]*|))(?=\s|\b)#is </code></pre> <p><strong>Code:</strong></p> <pre><code>$arr = array( 'http://www.domain.com/?foo=bar', 'http://www.that"sallfolks.com', 'This is really cool site: https://www.domain.net/ isn\'t it?', 'http://subdomain.domain.org', 'www.domain.com/folder', 'Hello! You can visit vertigofx.com/mysite/rocks for some awesome pictures, or just go to vertigofx.com by itself', 'subdomain.domain.net', 'subdomain.domain.edu/folder/subfolder', 'Hello! Check out my site at domain.net!', 'welcome.to.computers', 'Hello.Come visit oursite.com!', 'foo.bar', 'domain.com/folder', ); foreach($arr as $url) { $link = preg_replace_callback('#(\s|^)((?:https?://)?\w+(?:\.\w+)+(?&lt;=\.(net|org|edu|com))(?:/[^\s]*|))(?=\s|\b)#is', create_function('$m', 'if (!preg_match("#^(https?://)#", $m[2])) return $m[1]."&lt;a href=\"http://".$m[2]."\"&gt;".$m[2]."&lt;/a&gt;"; else return $m[1]."&lt;a href=\"".$m[2]."\"&gt;".$m[2]."&lt;/a&gt;";'), $url); echo $link . "\n"; </code></pre> <p><strong>OUTPUT:</strong></p> <pre><code>&lt;a href="http://www.domain.com/?foo=bar"&gt;http://www.domain.com/?foo=bar&lt;/a&gt; http://www.that"sallfolks.com This is really cool site: &lt;a href="https://www.domain.net"&gt;https://www.domain.net&lt;/a&gt;/ isn't it? &lt;a href="http://subdomain.domain.org"&gt;http://subdomain.domain.org&lt;/a&gt; &lt;a href="http://www.domain.com/folder"&gt;www.domain.com/folder&lt;/a&gt; Hello! You can visit &lt;a href="http://vertigofx.com/mysite/rocks"&gt;vertigofx.com/mysite/rocks&lt;/a&gt; for some awesome pictures, or just go to &lt;a href="http://vertigofx.com"&gt;vertigofx.com&lt;/a&gt; by itself &lt;a href="http://subdomain.domain.net"&gt;subdomain.domain.net&lt;/a&gt; &lt;a href="http://subdomain.domain.edu/folder/subfolder"&gt;subdomain.domain.edu/folder/subfolder&lt;/a&gt; Hello! Check out my site at &lt;a href="http://domain.net"&gt;domain.net&lt;/a&gt;! welcome.to.computers Hello.Come visit &lt;a href="http://oursite.com"&gt;oursite.com&lt;/a&gt;! foo.bar &lt;a href="http://domain.com/folder"&gt;domain.com/folder&lt;/a&gt; </code></pre> <p><strong>PS:</strong> This regex only supports http and https scheme in URL. So eg: if you want to support ftp also then you need to modify the regex a little.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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