tags:

views:

68

answers:

3

Hi can someone help me identify if a url is present in a string using PHP?

I want to pull in a full string i.e. "Hi please visit http://domain.com/12345 today" and strip out the full url not just the domain name.

Thanks

+2  A: 
altCognito
A: 

here's an example

$str = file_get_contents('http://www.sitepoint.com');

preg_match_all('~(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)~', $str, $matches);

print_r($matches);
Galen
+2  A: 

Take a look at this article from Jeff Atwood's blog "Coding Horror":

The Problem With URLs

VVS