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. Link to comment https://forums.phpfreaks.com/topic/14508-getting-everything-between-the-first-and-the-last/ 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 Link to comment https://forums.phpfreaks.com/topic/14508-getting-everything-between-the-first-and-the-last/#findComment-57457 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 Link to comment https://forums.phpfreaks.com/topic/14508-getting-everything-between-the-first-and-the-last/#findComment-57677 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] Link to comment https://forums.phpfreaks.com/topic/14508-getting-everything-between-the-first-and-the-last/#findComment-57875 Share on other sites More sharing options...
play_ Posted July 14, 2006 Author Share Posted July 14, 2006 ahhh. thanks a bunch Obsidian Link to comment https://forums.phpfreaks.com/topic/14508-getting-everything-between-the-first-and-the-last/#findComment-57914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.