Skip to content

Instantly share code, notes, and snippets.

@mikemix
Created January 10, 2014 07:25
Show Gist options
  • Save mikemix/8348170 to your computer and use it in GitHub Desktop.
Save mikemix/8348170 to your computer and use it in GitHub Desktop.
Get tag contents from html
<?php
/**
* @param string $tagName
* @param string $content
*/
function getTagContents($tagName, $content)
{
preg_match_all(sprintf('#<%1$s[^>]+>(.*?)</%1$s>#ism', $tagName), $content, $match);
return isset($match[1]) ? $match[1] : array();
}
$string='My <strong>dog</strong> is <strong>missing</strong>.';
print_r(getTagContents('strong', $string));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment