I have a string that has html tags in it. From the string I want to remove anchor tags from the string that contains the word 'pluginfile.php' in their URL.
$string = "<div class=\"container\">
<div class=\"row\">
<div class=\"col-md-12\">
<div class=\"detail-content\">
<h1>COURSE OVERVIEW</h1>
<div class=\"text-center\">
<a href=\"http://localhost/moodle/webservice/pluginfile.php/670/course/summary/0/video1.mp4\">video1.mp4</a>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ultricies neque eget turpis pretium eleifend. Sed laoreet ultricies elit, id semper leo venenatis at"
`
$string = "<div class=\"container\">
<div class=\"row\">
<div class=\"col-md-12\">
<div class=\"detail-content\">
<h1>COURSE OVERVIEW</h1>
<div class=\"text-center\">
<a href=\"http://localhost/moodle/webservice/pluginfile.php/670/course/summary/0/video1.mp4\">video1.mp4</a>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ultricies neque eget turpis pretium eleifend. Sed laoreet ultricies elit, id semper leo venenatis at"
$allTags = split('<',string);
$temp=0
for($temp=0;$temp<allTags.lenght();$temp++){
if(strpos($allTags,"***requiredString***")){
$allTags[temp] = "";
}
}
echo(join('<', allTags));
`
this will first split all the tags into array then loop over the array and replace the tag with your required string with an empty string and then join the tags with '<'