Lectrician Posted June 6, 2014 Share Posted June 6, 2014 Hi. I am trying to extract the main url from a string. For example. I want to extract: "http://google.com" from "http://google.com/search/pic.jpg" "https://secure.co.uk" from "https://secure.co.uk/secure/secure.gif" I am able to do this with this code, where $url is the url: preg_match("http://(.*?)/", $url, $matches); preg_match("https://(.*?)/", $url, $matches); Is there away to consolidate this into one regex search? Or am I being picky? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/289023-https-url-regex/ Share on other sites More sharing options...
Ch0cu3r Posted June 6, 2014 Share Posted June 6, 2014 No need for regex, Try using parse_url Quote Link to comment https://forums.phpfreaks.com/topic/289023-https-url-regex/#findComment-1482096 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.