Skip to content

Instantly share code, notes, and snippets.

@webmechanicx
Created February 29, 2016 22:30
Show Gist options
  • Save webmechanicx/b74bf4db02603a0c6821 to your computer and use it in GitHub Desktop.
Save webmechanicx/b74bf4db02603a0c6821 to your computer and use it in GitHub Desktop.
Simple PHP function to find anything between a tag
<?php
function betweenTags($string, $tagname)
{
$pattern = "#<\s*?$tagname\b[^>]*>(.*?)</$tagname\b[^>]*>#s";
preg_match($pattern, $string, $matches);
return $matches[1];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment