SoundreameR Posted July 2, 2007 Share Posted July 2, 2007 Hi again guyz... I have a very dumb problem... If I have a html output, how can I get only the content of a specific tag, removing everything else, including TEXT. strip_tags helped in removing some tags, but the text is still there... Ex.: If there is a bunch of code, I want to get only the content of <h2></h2> tags. Like this: Input code: bla bla <br> muhaha <br> <h2>[NEEDED CONTENT]<h2> foo foo foo <br> the bar <br> emo mu <br> <h2>[NEEDED CONTENT 2]<h2> etc... Output code: <h2>[NEEDED CONTENT]<h2> <h2>[NEEDED CONTENT 2]<h2> Quote Link to comment Share on other sites More sharing options...
rea|and Posted July 2, 2007 Share Posted July 2, 2007 Try this: preg_match_all('/<h2>.*?<\/h2>/is',$your_text,$mth); echo implode("\n",$mth[0]); Quote Link to comment Share on other sites More sharing options...
SoundreameR Posted July 2, 2007 Author Share Posted July 2, 2007 Thanks dude! It works very nice! Now how about a pattern to filter the href data of an anchor? Quote Link to comment Share on other sites More sharing options...
rea|and Posted July 2, 2007 Share Posted July 2, 2007 Look just few 3d below this one http://www.phpfreaks.com/forums/index.php/topic,147173.msg631053.html#msg631053 Quote Link to comment Share on other sites More sharing options...
SoundreameR Posted July 2, 2007 Author Share Posted July 2, 2007 Thanks 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.