Preg_match_all

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
torvald_helmer
Forum Newbie
Posts: 4
Joined: Sun Nov 26, 2006 6:51 am

Preg_match_all

Post by torvald_helmer »

I use preg_match_all to extract content from a html-file, like this:

preg_match_all('#<tr><td class="felt">(.*?)</td><td>#s', $content, $matches);
print_r($matches);

This extract all text inside the table-cells, and this work perfectly!

It return one index of an array like this:
[0] => Postgraduate<br/>

As you see, this index 0 consist of text and a tag.

Sometimes there is additional tag's inside a table-cell defined in the preg_match_all line above...
How can I remove this extra tag, it is mostly a break-tag, but sometime a p-element.

Any tips?? :)
Adrianc333
Forum Newbie
Posts: 14
Joined: Sat Feb 17, 2007 5:44 am
Location: South Yorkshire, UK

Post by Adrianc333 »

Try

echo $matches[1];
torvald_helmer
Forum Newbie
Posts: 4
Joined: Sun Nov 26, 2006 6:51 am

Post by torvald_helmer »

This just prints the text, ok. But the tag is still there, just not showing the browser.

I want to remove the tags from the array's entries.
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

There is probably a nice regex to exclude <br/> in your actualy preg_match ... but you could probably just loop through your results and str_replace <br/> with '' for now if its not too much data.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Post Reply