dongyi1111 2017-02-01 06:51
浏览 48

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

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"
  • 写回答

1条回答 默认 最新

  • duanpu8830 2017-02-01 07:11
    关注

    `

    $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 '<'

    评论

报告相同问题?