Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created September 18, 2019 15:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/bd2a5f33ad751a1d754e2a237f87b64f to your computer and use it in GitHub Desktop.
Save phpfiddle/bd2a5f33ad751a1d754e2a237f87b64f to your computer and use it in GitHub Desktop.
[ Posted by Expangea ] PHP preg_match_all xml tags
<?php
$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='';
$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