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? Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 30, 2007 Share Posted November 30, 2007 /<a[^>]+href=([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/ Quote Link to comment Share on other sites More sharing options...
jordanwb Posted December 1, 2007 Author Share Posted December 1, 2007 That did it, Thanks. Quote Link to comment 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.