get everything between <tag> and </tag> with php
I'm trying to grab a string within a string using regex.
I've looked and looked but I can't seem to get any of the examples I have to work.
I need to grab the html tags <code> and </code> and everything in between them.
Then I need to pull the matched string from the parent string, do operations on both,
then put the matched string back into the parent string.
Here's my code:
$content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. <code>Donec sed erat vel diam ultricies commodo. Nunc venenatis tellus eu quam suscipit quis fermentum dolor vehicula.</code>"
$regex='';
$code = preg_match($regex, $text, $matches);
I've already tried these without success:
$regex = "/<code\s*(.*)\>(.*)<\/code>/";
$regex = "/<code>(.*)<\/code>/";