greenheart Posted October 6, 2009 Share Posted October 6, 2009 hello, I have a string with lots of http addresses in it and the one I want has the unique form: url('http:// xxxxxx ') where xxxxx is the usual remainder of the webaddress (ignore the spaces). What pattern do I need for this to be extracted via a preg_match? Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/ Share on other sites More sharing options...
newbtophp Posted October 6, 2009 Share Posted October 6, 2009 <?php $url = 'http://www.website.com'; preg_match('@^(?:http://)?([^/]+)@i',$url, $matches); echo $matches[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/#findComment-931790 Share on other sites More sharing options...
greenheart Posted October 6, 2009 Author Share Posted October 6, 2009 Hello thanks for the effort I tried that but it only gives me "array array array". An example url is url('http://cnd.example-page.com/random/561/36075591.jpg') with the url(' included at the beginning. Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/#findComment-931806 Share on other sites More sharing options...
cags Posted October 6, 2009 Share Posted October 6, 2009 And how did you use the supplied code? Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/#findComment-931822 Share on other sites More sharing options...
newbtophp Posted October 6, 2009 Share Posted October 6, 2009 Im guessing you have an url() function? so you'd call it by: <?php $url = 'http://cnd.example-page.com/random/561/36075591.jpg'; preg_match('@^(?:http://)?([^/]+)@i',$url, $matches); url($matches[1]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/#findComment-931830 Share on other sites More sharing options...
greenheart Posted October 6, 2009 Author Share Posted October 6, 2009 I don't have an url function. It gives a fatal error function url() undefined. Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/#findComment-931897 Share on other sites More sharing options...
salathe Posted October 6, 2009 Share Posted October 6, 2009 What pattern do I need for this to be extracted via a preg_match? You could start off with something like the following, then refine it to suit your particular needs: <?php $subject = " http://php.net is awesome url('http://blah.foo.com') phpfreaks rocks! "; preg_match("#url\('(http://[^']+)'\)#", $subject, $match); $url = $match[1]; echo $url; // http://blah.foo.com ?> Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/#findComment-931911 Share on other sites More sharing options...
greenheart Posted October 6, 2009 Author Share Posted October 6, 2009 What pattern do I need for this to be extracted via a preg_match? You could start off with something like the following, then refine it to suit your particular needs: <?php $subject = " http://php.net is awesome url('http://blah.foo.com') phpfreaks rocks! "; preg_match("#url\('(http://[^']+)'\)#", $subject, $match); $url = $match[1]; echo $url; // http://blah.foo.com ?> Thank you, that works. Thanks everyone. Problem solved. Quote Link to comment https://forums.phpfreaks.com/topic/176738-solved-preg_match_all-problem/#findComment-931960 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.