Epic Posted August 31, 2007 Share Posted August 31, 2007 Hey there, I've tried searching around the forum but I couldn't find a post addressing exactly what I'm trying to do. Sorry if something similar has already been posted. What I'm trying to do is get the content between two tags. For instance, if I had [PRICE]29.99[/PRICE], I'd want to just echo 29.99. The tags aren't always that simple though, sometimes it'll be some complex HTML code. I've done this using explode(), but even I have a feeling that is not the greatest way to do it. Thanks in advance for your help. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 0 is the entire match and 1 is the captured content: <pre> <?php $string = '[PRICE]29.99[/PRICE]'; preg_match('#\[PRICE\](.*?)\[/PRICE\]#s', $string, $matches); print_r($matches); ?> </pre> Quote Link to comment Share on other sites More sharing options...
Epic Posted August 31, 2007 Author Share Posted August 31, 2007 Thank you very much! It works great 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.