N-Bomb(Nerd) Posted June 16, 2009 Share Posted June 16, 2009 I'm currently using this preg function: preg_match_all('/<div class="vlc east coast">(.*)<\/div>/i', $Page, $Content); However, it doesn't seem to give me the output of what's inside of that div. The actual div looks like this: <div class="vlc east coast"> Visit Us:<br><img src='visit.jpg' width='250' height='250 alt='Visit Us' /> </div> What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Alex Posted June 16, 2009 Share Posted June 16, 2009 Probably because of the white space. Try this: preg_match_all("/<div class=\"vlc east coast\">((.|\s)*)<\/div>/i", $Page, $Content) This works: $str = '<div class="vlc east coast"> Visit Us:<br><img src=\'visit.jpg\' width=\'250\' height=\'250\' alt=\'Visit Us\' /> </div>'; $pattern = "/<div class=\"vlc east coast\">((.|\s)*)<\/div>/i"; if(preg_match_all($pattern, $str, $matches)) echo $matches[1][0]; Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 16, 2009 Share Posted June 16, 2009 The dot doesn't match new lines by default; you'll have to add the s modifier (after the last slash, next to the i modifier). You should also make the star lazy, by adding a question mark right after it. More efficient. And know that a nested div will stop the match. But if there aren't any, you're fine 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.