ManOfSpear Posted July 8, 2009 Share Posted July 8, 2009 Hey guys, I'm very new to PHP & Regex. I was wondering if it's possible to extract all possible URL's from a string and add it to an array. If anyone can help me I would be very grateful. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/165122-solved-extract-all-urls-from-a-text/ Share on other sites More sharing options...
.josh Posted July 8, 2009 Share Posted July 8, 2009 preg_match_all('~https?://[^"\'\s]+~i',$string,$links); echo "<pre>"; print_r($links); Quote Link to comment https://forums.phpfreaks.com/topic/165122-solved-extract-all-urls-from-a-text/#findComment-871019 Share on other sites More sharing options...
ManOfSpear Posted July 8, 2009 Author Share Posted July 8, 2009 preg_match_all('~https?://[^"\'\s]+~i',$string,$links); echo "<pre>"; print_r($links); Thank you my friend, it managed to get every single link which is amazing since every other regex I have tried failed badly. Quote Link to comment https://forums.phpfreaks.com/topic/165122-solved-extract-all-urls-from-a-text/#findComment-871268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.