$resource = "THIS IS ABOUT WWW.JONAKCOMPUTERS.COM, HTTP://HIGHLOW.COM, AND TESTINGSERVER1.COM"
and I want to pull out the three urls into another string that is similar to:
$all_urls = "JONAKCOMPUTERS.COM - HIGHLOW.COM - TESTSERVER1.COM
I found this by someone else:
$pattern = '#(www\.|https?:\/\/){1}[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\S*)#i';
preg_match_all($pattern, $string, $matches, PREG_PATTERN_ORDER);
But it doesn’t pull “jonakcomputers.com” only “http://url” or “www.url”
Sorry for the caps, I just wanted to make it clear that its not case sensitive at the end. I can always capitalize it. I need to do this before the page loads, so it could be javascript or php.
If I could pull one out I think I could do a loop to keep checking for new ones till it runs out.
Thanks for anyone willing to help out.
I ran your code in a console, just adjusting the variable name in the last snippet so that:
What you see in the preg_match return is a multidimensional array w/ the following:
0: Full Matches
1: SubPattern 1 matches
2: SubPattern 2 matches
The only fix I see is that you’ll need to adjust the RegExp slightly to account for the lack of ww or http. so just use this for pattern:
and your $matches should now contain all 3.