Skip to content

Instantly share code, notes, and snippets.

Created September 18, 2019 15:24
What would you like to do?
[ Posted by Expangea ] PHP preg_match_all xml tags
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. <code>Donec sed erat</code> vel diam ultricies commodo.
Nunc venenatis tellus eu quam suscipit quis fermentum <code>dolor vehicula.</code> fin";
$regex = '#<\s*?code\b[^>]*>(.*?)</code\b[^>]*>#s';
$code = preg_match_all($regex, $text, $matches);
echo $text."<hr>";
echo var_export($matches,true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment