jordanwb Posted November 30, 2007 Share Posted November 30, 2007 What I'm trying to do is get all the links within the <a href=""> out and print them to the page, one after another. I have everything but the regex (assuming it can be done) to do so. Any help? Link to comment https://forums.phpfreaks.com/topic/79607-solved-trying-to-extract-tags-out-of-file/ Share on other sites More sharing options...
effigy Posted November 30, 2007 Share Posted November 30, 2007 Assuming all href's are double-quoted: preg_match_all('%<a[^>]+href="([^"]+)%', $data, $matches); array_shift($matches); print_r($matches); Link to comment https://forums.phpfreaks.com/topic/79607-solved-trying-to-extract-tags-out-of-file/#findComment-403195 Share on other sites More sharing options...
jordanwb Posted November 30, 2007 Author Share Posted November 30, 2007 In some of the files I'm trying to read the href's don't have quotes: <a href=http://google.ca>Google</a> What you suggested does work so thanks for that. Link to comment https://forums.phpfreaks.com/topic/79607-solved-trying-to-extract-tags-out-of-file/#findComment-403245 Share on other sites More sharing options...
effigy Posted November 30, 2007 Share Posted November 30, 2007 /<a[^>]+href=([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/ Link to comment https://forums.phpfreaks.com/topic/79607-solved-trying-to-extract-tags-out-of-file/#findComment-403246 Share on other sites More sharing options...
jordanwb Posted December 1, 2007 Author Share Posted December 1, 2007 That did it, Thanks. Link to comment https://forums.phpfreaks.com/topic/79607-solved-trying-to-extract-tags-out-of-file/#findComment-403341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.