chick3n Posted August 1, 2007 Share Posted August 1, 2007 String 1: "<tag>text in here<ins>more text</tag>" String 2: "<tag>text in here</tag>" I want to write a expression that will stop at the end of the tag and get the text between it or stop at a predefined tag and get the text between that. So in string 1 i want to get "text in here" and stop at <ins> and in string 2 i want the same text but stop at </tag> instead. My regex for getting the text inbetween the tags is: /<span class=\"\">(.*)<\/span>/smU But i cannot get it to do an either or type of thing with <ins> || </span> Link to comment https://forums.phpfreaks.com/topic/62852-regex-for-stopping-at-either-tags/ Share on other sites More sharing options...
effigy Posted August 1, 2007 Share Posted August 1, 2007 <pre> <?php $tests = array( '<tag>text in here<ins>more text</tag>', '<tag>text in here</tag>', '<tag></tag>', '<tag>a</tag><tag>b</tag>' ); foreach ($tests as $test) { echo htmlspecialchars($test), '<br>'; preg_match('#<[^>]+>(.*?)<[^>]+>#', $test, $matches); echo htmlspecialchars($matches[1]); echo '<hr>'; } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/62852-regex-for-stopping-at-either-tags/#findComment-312892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.