$html = preg_replace('/
]*>[\s ]*<\/p>/u', '', $html); $html = trim($html); preg_match_all('/
]*>.*?<\/p>/is', $html, $matches); if (count($matches[0]) === 1) { return preg_replace( ['/^\s*
]*)>/i', '/<\/p>\s*$/i'], ['', ''], $html ); } return $html; } }