PHP: Strip Specific HTML tags from giving String

The below function will help us to Strip given HTML tag to strip from HTML string. In this function, we can able to pass the starting and ending tags of the specific string enclosed.

Example:

function strip_specific_tags($startTag, $endTag, $htmlString) {
  $stripResponse = preg_replace($startTag . ' (.*?)' . $endTag . '#', '', $htmlString);
  return $stripResponse;
}

 

$startTag = '<span class="stripwrapper">'; // Start tag with class. We can able to specify without class also.
$endTag = '</span>'; // Ending tag.
$htmlString = '<div class="welcome">
Welcome to CodeExpertz. A Blog site to discuss Technical talks. 
<span class="stripwrapper"> Strip This content </span>
<p>Welcome to CodeExpertz. A Blog site to discuss Technical talks.</p>
</div>';
print strip_specific_tags($startTag, $endTag, $htmlString);
 
Output:
<div class="welcome">
Welcome to CodeExpertz. A Blog site to discuss Technical talks. 
<p>Welcome to CodeExpertz. A Blog site to discuss Technical talks.</p>
</div>
Category: