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> Quote Link to comment 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> 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.