Skip to content

Instantly share code, notes, and snippets.

@seanbuscay
Created September 25, 2013 15:57
Show Gist options
  • Save seanbuscay/6701791 to your computer and use it in GitHub Desktop.
Save seanbuscay/6701791 to your computer and use it in GitHub Desktop.
<?php
/**
 *
 * @strip a single HTML/XML tag from a string
 *
 * @param array $tags The tags to strip
 *
 * @param string The string to strip from
 *
 * @return string
 *
 */
function stripSingleTags($tags, $string)
{
    foreach( $tags as $tag )
    {
        $string = preg_replace('#</?'.$tag.'[^>]*>#is', '', $string);
    }
    return $string;
}
/*** example usage ***/
$string = '<p>stuff</p><span>more <span class="foo">and even>< more</span> stuff here</span>';
$tags = array('h1', 'span');
echo stripSingleTags($tags, $string);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment