June 4, 2012

preg_replace to replace specific tag in string

preg_replace to replace specific tag in string


if ( ! function_exists('clean_this'))
{
function clean_this($tag_name,$html)
{
return preg_replace("/(<".$tag_name.">.+?)+(<\/".$tag_name.">)/i", '', $html);
}
}

Keep hyperlink text and remove href

$cart_item = '<a>'.preg_replace("/\<a(.*)\>(.*)\<\/a\>/iU", "$2", $cart_item).'</a>';

Last updated: June 19, 2016