play_ Posted July 13, 2006 Share Posted July 13, 2006 Can it be done?I plan on using preg_match_all with this.now, i know that preg_match_all("\<.b>(.*)<\/b>/", $a, $e) will match everything between <.b> and </b> and insert it into the array.I only need to get everything between the first > and last < on a line, considering there will be more of them in between. Quote Link to comment Share on other sites More sharing options...
obsidian Posted July 13, 2006 Share Posted July 13, 2006 actually, i think you've got it slightly backwards. if you want EVERYTHING between the first and last characters you put in, you need to use the (.*)... remember that the '.' is greedy. here's the difference:[code]<?php$text = "<b>asdf</b><i>asdf</i><p></p>";// first, get only what's between the bold tags:preg_match('|<b>(.+?)</b>|i', $text, $match);echo $match[1]; // outputs "asdf"// now, here's getting everything between first ">" and last "<"preg_match('|>(.*)<|', $text, $match);echo htmlentities($match[1]); // outputs "asdf</b><i>asdf</i><p>"?>[/code]hope this helps Quote Link to comment Share on other sites More sharing options...
play_ Posted July 14, 2006 Author Share Posted July 14, 2006 Thanks Obsidian.I can't get it to work on my code though.Here's a sample line:[code]<</font><font color="#0000bb">f</font><font color="#007700">><br><</font><font color="#0000bb">f</font><font color="#007700">></font><font color="#ff8000">// news query | display the news>[/code]The < and > actually got replaced by < and > (its from a highlight_string() function).So if i used[code]preg_match('|>l(.*)|<', $text, $match);[/code]should do it right? because i can't get it to Quote Link to comment Share on other sites More sharing options...
obsidian Posted July 14, 2006 Share Posted July 14, 2006 [quote author=play_ link=topic=100467.msg396751#msg396751 date=1152838677]Thanks Obsidian.I can't get it to work on my code though.Here's a sample line:[code]<</font><font color="#0000bb">f</font><font color="#007700">><br><</font><font color="#0000bb">f</font><font color="#007700">></font><font color="#ff8000">// news query | display the news>[/code]The < and > actually got replaced by < and > (its from a highlight_string() function).So if i used[code]preg_match('|>l(.*)|<', $text, $match);[/code]should do it right? because i can't get it to[/quote]you've got your closing pipe in the wrong place:[code]<?phppreg_match('|\<(.*)\>|', $text, $match);?>[/code] Quote Link to comment Share on other sites More sharing options...
play_ Posted July 14, 2006 Author Share Posted July 14, 2006 ahhh. thanks a bunch Obsidian 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.