PHP regex to obtain img class

D-Spayre

New Member
I have a bunch of text and HTML and what I want to achieve is gather all css classes of img tags that match a certain pattern and place them in a loop.For example:\[code\]<img src="http://stackoverflow.com/questions/3544258/sample1.gif' class="get-this-tag-1" />This is text. This is text. This is text. This is text. This is text. This is text. <img src="http://stackoverflow.com/questions/3544258/sample2.gif' class="image" />This is text. This is text. This is text. This is text. This is text. This is text. <img src="http://stackoverflow.com/questions/3544258/sample3.gif' class="get-this-tag-2" />This is text. This is text. This is text. This is text. This is text. This is text.\[/code\]In the sample we have 3 images with different classes: get-this-tag-1, image and get-this-tag-2. I only want to retrieve the classes that match get-this-tag- and have them in a loop.\[code\]foreach ($classes as $class) { //do something}\[/code\]Is this possible? Or is there a more optimal way of doing what I want to achieve?Thank you in advance!
 
Back
Top