簡體   English   中英

如何在php中搜索和刪除字符串

[英]How to search and delete string in php

我試圖將Twitter的RSS提要(將從現在開始消失的一種)與Feedburner一起使用,但是xml中的一行代碼在feedburner中引起了解析錯誤。 我想這是

的xmlns:嘰嘰喳喳= “http://api.twitter.com”

我正在尋找一種以喜歡的方式將此信息提供給feedburner的方法:即php,其中包括我自己站點上的xml中的RSS xml頁面的內容(刪除了有問題的字符串)。 包括xml內容是小菜一碟-我所需要的只是一段代碼來說明iff字符串片段== xmlns:twitter="http://api.twitter.com"然后是string frament =“”。

有人對此有語法的想法嗎?

您可以嘗試使用str_replace

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

另外,您可以嘗試對http://api.twitter.com進行urlencode

或者,您可以使用preg_replace函數: http : //php.net/manual/zh/function.preg-replace.php

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM