discussnow Posted November 21, 2008 Share Posted November 21, 2008 Hello, I'm currently working on using regex to scrape a few lines of code and display it: $scrape = file_get_the_contents($url) ; $regex = '/<td class="info"> <a href="(.+?)" title=/'; preg_match($regex,$scrape,$results); var_dump($results); echo $results; and this is the result I get : array(2) { [0]=> string(61) " Quote Link to comment https://forums.phpfreaks.com/topic/133691-regex-issues/ Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 echo $scrape before running preg_match Quote Link to comment https://forums.phpfreaks.com/topic/133691-regex-issues/#findComment-695655 Share on other sites More sharing options...
.josh Posted November 22, 2008 Share Posted November 22, 2008 Hello, I'm currently working on using regex to scrape a few lines of code and display it: $scrape = file_get_the_contents($url) ; $regex = '/<td class="info"> <a href="(.+?)" title=/'; preg_match($regex,$scrape,$results); var_dump($results); echo $results; and this is the result I get : array(2) { [0]=> string(61) " so...what's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/133691-regex-issues/#findComment-696011 Share on other sites More sharing options...
nrg_alpha Posted November 23, 2008 Share Posted November 23, 2008 a) How are we to know which URL you are scraping? (file_get_the_contents($url) doesn't tell us what the source code is) b) In your pattern '/<td class="info"> <a href="(.+?)" title=/', I hope you realise that those spaces between the td tag and the a tag are actually needed to be matched (if you do not desire those spaces, remove them from the pattern). c) an answer like 'and this is the result I get : array(2) { => string(61) " ' doesn't tell us squat. My advice would be to provide a sample of the URL code you are trying to scrape, as your post tells us nothing (other than the involement of a td tag and an a tag (with some spaces in between for some odd reason). Quote Link to comment https://forums.phpfreaks.com/topic/133691-regex-issues/#findComment-696646 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.