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> Link to comment https://forums.phpfreaks.com/topic/58065-solved-regex-problem-again/ 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]); Link to comment https://forums.phpfreaks.com/topic/58065-solved-regex-problem-again/#findComment-287926 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? Link to comment https://forums.phpfreaks.com/topic/58065-solved-regex-problem-again/#findComment-288257 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 Link to comment https://forums.phpfreaks.com/topic/58065-solved-regex-problem-again/#findComment-288308 Share on other sites More sharing options...
SoundreameR Posted July 2, 2007 Author Share Posted July 2, 2007 Thanks Link to comment https://forums.phpfreaks.com/topic/58065-solved-regex-problem-again/#findComment-288325 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.