Get all between div tags

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Get all between div tags

Post by shiznatix »

I am trying to get all of the html between 2 div tags but I am having some troubles. Here we goooooo:

Code: Select all

preg_match('#<div class="middleColumn">(.*)<\/div>#m', $cont, $matches);

dump($matches);
Obviously what I am going for is between <div class="middleColumn"> and </div> but I get no results. Any help would be grand.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Get all between div tags

Post by Burrito »

Code: Select all

preg_match('/<div class="middleColumn">(.*?)<\/div>/mi', $cont, $matches);

dump($matches);
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Thanks but to no avail as that did not work
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

#<div class="middleColumn">(.*?)</div>#si
and preg_match_all() probably.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

yes thank you much. success
Post Reply