following code is used to find url from a string with php. Here is the code:
$string = \"Hello http://www.bytes.com world www.yahoo.com\";
preg_match(\'/(htt
If you want to detect something like stackoverflow.com
, then you're going to have to check for all possible TLDs to rule out something like Web 2.0
, which is quite a long list. Still, this is also going to match something as ASP.NET
etc.
The regex would looks something like this:
$hypertext = preg_replace(
'{\b(?:http://)?(www\.)?([^\s]+)(\.com|\.org|\.net)\b}mi',
'$1$2$3',
$text
);
This only matches domains ending in .com, .org and .net... as previously stated, you would have to extend this list to match all TLDs