design@brightcherry.co.uk
Call us on   01279- 729075

The following function puts all URLs/links from a string into an array. The function uses the preg_match function, and looks for URLs/links with http/https. Please note, the function does NOT search for hyperlink tags ()- it looks for URL’s.

1
2
3
4
5
6
7
8
9
function getUrls($string) {
 $regex = '/https?\:\/\/[^\" ]+/i';
 preg_match_all($regex, $string, $matches);
 return ($matches[0]);
}
 
$urls = getUrls($string);
 
print_r($urls);

This blog post was written on 13 Feb 2013 by Maruf, and has 0 Comments so far

Learning & sharing

This is where we store some of our Web Development thoughts, tips and tricks for both our own uses and for others to learn from. Sharing is caring.

Please feel free to contrinute to our blog posts; perhaps even teach us a few tricks of your own. We'd love to hear your thoughts.

Social

Feel free to share this blog post and/or subscribe to our RSS feed :)