【问题标题】:Remove contextual links inside a description tag of a feed without losing the value删除提要的描述标签内的上下文链接而不丢失价值
【发布时间】:2012-05-30 11:24:21
【问题描述】:

我想知道是否可以删除 XML 提要的 标记内的所有上下文链接。

这是我在 PHP 文件中得到的内容:

<?php
    header('Content-type: text/xml');
    $url = "http://www.Example.com/articles.rss";
    $page = file($url);

    foreach ($page as $part)
    {
        echo $part;
    }
?>

查看 XML 提要的屏幕截图:

【问题讨论】:

    标签: php xml parsing replace feed


    【解决方案1】:

    使用 preg_replace 查找链接并将其替换为空行。

    匹配打开&lt;a&gt;标签然后关闭&lt;/a&gt;:

    foreach ($page as $part)
    {
      $part = preg_replace("/<a\b[^>]*>/", "", $part);
      $part = preg_replace("/<\/a>/", "", $part);
      echo $part;
    }
    

    现场演示:http://www.rubular.com/r/9dWWxbhzLn

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-16
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多