从包含URL中特定单词的字符串中删除锚标记

时间:2017-02-01 06:51:27

标签: php string

我有一个包含html标签的字符串。从字符串我想从包含单词' pluginfile.php'的字符串中删除锚标记。在他们的URL中。

$string = "<div class=\"container\">\r\n<div class=\"row\">\r\n<div class=\"col-md-12\">\r\n<div class=\"detail-content\">\r\n<h1>COURSE OVERVIEW</h1>\r\n<div class=\"text-center\">\r\n<a href=\"http://localhost/moodle/webservice/pluginfile.php/670/course/summary/0/video1.mp4\">video1.mp4</a>\r\n</div>\r\n<p>\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ultricies neque eget turpis pretium eleifend. Sed laoreet ultricies elit, id semper leo venenatis at"

1 个答案:

答案 0 :(得分:0)

  

`

$string = "<div class=\"container\">\r\n<div class=\"row\">\r\n<div class=\"col-md-12\">\r\n<div class=\"detail-content\">\r\n<h1>COURSE OVERVIEW</h1>\r\n<div class=\"text-center\">\r\n<a href=\"http://localhost/moodle/webservice/pluginfile.php/670/course/summary/0/video1.mp4\">video1.mp4</a>\r\n</div>\r\n<p>\r\nLorem 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));

`

这将首先将所有标记拆分为数组,然后循环遍历数组并使用空字符串替换标记所需的字符串,然后使用&#39;&lt;&#39;

加入标记