使用php从长字符串中删除特定字符串

时间:2014-10-03 12:31:06

标签: php

如何使用php从此$string删除 {SEP},日期,名称,冒号(:)

$string = "{SEP}09-27-2014 19:38 PM alex : hmm..{SEP}{SEP}09-27-2014 20:04 PM alex : note here..{SEP}{SEP}09-27-2014 20:05 PM alex : testing{SEP}
{SEP}09-27-2014 20:07 PM alex : 1{SEP}{SEP}09-27-2014 20:29 PM alex : abc{SEP}{SEP}09-27-2014 20:30 PM alex : nice..{SEP}{SEP}09-27-2014 
20:32 PM alex : checking by pressing the save button.{SEP}{SEP}09-27-2014 20:32 PM alex : Ok now check without save button.{SEP}";

这样看起来像这样:

hmm.. note here..testing 1 abc nice..checking by pressing the save button. Ok now check 
without save button.

1 个答案:

答案 0 :(得分:1)

preg_replace是一个很好的起点:

echo preg_replace("/\{SEP\}(.+?)\s:\s(.+?)\{SEP\}/m", "$2", $string);