iHack Posted October 15, 2007 Share Posted October 15, 2007 I need to get everything between <textarea name="textarea" rows="5"> and </textarea> I also need the regex for between two <br> 's Thanks, iHack Quote Link to comment https://forums.phpfreaks.com/topic/73344-get-everything-between-this/ Share on other sites More sharing options...
roopurt18 Posted October 15, 2007 Share Posted October 15, 2007 Regexps are best used when you're matching a specific pattern, which means you don't know the characters in advance. In this case, you know the exact starting and ending points of the string, so I'd recommend a combination of strpos and substr to accomplish what you need. <?php $srch1 = '<textarea name="textarea" rows="5">'; $srch2 = '</textarea>'; $pos1 = strpos($the_string, $srch1); if($pos1 !== FALSE){ $pos1 += strlen($srch1); $pos2 = strpos($the_string, $srch2, $pos1); if($pos2 !== FALSE){ $substr = substr($the_string, $pos1, $pos2 - $pos1); echo $substr; } } ?> That may be slightly faster than invoking the regexp engine. Also, I've had trouble in the past using regexps on very large strings so for things that could be potentially large I try to avoid them. I didn't test that code, some of the offsets may be off by 1 so add '+ 1' as necessary. Quote Link to comment https://forums.phpfreaks.com/topic/73344-get-everything-between-this/#findComment-370049 Share on other sites More sharing options...
iHack Posted October 15, 2007 Author Share Posted October 15, 2007 Thanks and $the_string is the string that I want to search, correct? Quote Link to comment https://forums.phpfreaks.com/topic/73344-get-everything-between-this/#findComment-370057 Share on other sites More sharing options...
roopurt18 Posted October 15, 2007 Share Posted October 15, 2007 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/73344-get-everything-between-this/#findComment-370062 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.