0

I want to get all urls from mixed string. My string:

#EXTM3U #EXT-X-TARGETDURATION:10 #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:10, http://media.com/S1/HLS_VOD/26c2_1561/2500/segm000000.ts?key=49bfee85b05d117a2906368428094e94 #EXTINF:10, http://media.com/S1/HLS_VOD/26c2_1561/2500/segm000001.ts?key=49bfee85b05d117a2906368428094e94 #EXTINF:10, http://media.com/S1/HLS_VOD/26c2_1561/2500/segm000002.ts?key=49bfee85b05d117a2906368428094e94 #EXTINF:10, http://media.com/S1/HLS_VOD/26c2_1561/2500/segm000003.ts?key=49bfee85b05d117a2906368428094e94 #EXTINF:10, http://media.com/S1/HLS_VOD/26c2_1561/2500/segm000004.ts?key=49bfee85b05d117a2906368428094e94 #EXTINF:10, http://media.com/S1/HLS_VOD/26c2_1561/2500/segm000005.ts?key=49bfee85b05d117a2906368428094e94 #EXTINF:10, 

And my php code:

function getUrls($string) { $regex = '/https?\:\/\/[^\" ]+/'; preg_match_all($regex, $string, $matches); //return (array_reverse($matches[0])); return ($matches[0]); 

}

$urls = getUrls($videourlget); print_r($urls); 

But it not return urls. I want to return only URL-s from string. Any idea?

3
  • Your string have text containing href but your regex depends on it. Commented Jun 16, 2014 at 19:58
  • i changed code. please look Commented Jun 16, 2014 at 20:06
  • @user3710676: Your regex currently matches newlines as well. Change the expression to ~https?://\S+~. See demo. Commented Jun 16, 2014 at 20:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.