【问题标题】:How to search and delete string in php如何在php中搜索和删除字符串
【发布时间】:2012-11-05 14:25:14
【问题描述】:

我正在尝试将 Twitter 的 RSS 提要(从现在起一年后将消失的提要)与 Feedburner 一起使用,但 xml 中的一行代码导致 feedburner 出现解析错误。我觉得是

xmlns:twitter="http://api.twitter.com"

我正在寻找一种方法以它喜欢的方式将此信息提供给 feedburner:即 php 在我自己的站点上的 xml 中包含 RSS xml 页面的内容(删除了有问题的字符串)。包括 xml 内容是小菜一碟 - 我只需要一段代码来说明 iff string fragment == xmlns:twitter="http://api.twitter.com" 然后 string frament = ""。

有人知道这个的语法吗?

【问题讨论】:

    标签: php xml regex


    【解决方案1】:

    你可以试试str_replace:

    str_replace('xmlns:twitter="http://api.twitter.com"', '', $string);
    

    另外,你可以试试urlencodehttp://api.twitter.com

    【讨论】:

      【解决方案2】:

      或者,您可以使用 preg_replace 功能: http://php.net/manual/en/function.preg-replace.php

      <?php
      $string = 'string to be searched';
      $pattern = 'a particular pattern';
      $replacement = ''; //deletion
      echo preg_replace($pattern, $replacement, $string);
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-05
        • 1970-01-01
        • 2013-06-16
        • 2015-10-11
        • 2012-07-23
        • 2012-10-31
        • 1970-01-01
        相关资源
        最近更新 更多