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? Link to comment https://forums.phpfreaks.com/topic/162457-solved-preg_match_all-problem/ 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]; Link to comment https://forums.phpfreaks.com/topic/162457-solved-preg_match_all-problem/#findComment-857500 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 Link to comment https://forums.phpfreaks.com/topic/162457-solved-preg_match_all-problem/#findComment-857505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.