基本上,我有一个字符串,我需要搜索并删除其中的每个 SECOND 出现。
这是我的字符串的样子($s
):
question1,answer1,answer2,answer3,answer4
question2,answer1,answer2,answer3,answer4
question3,answer1,answer2,answer3,answer4
这是我的代码目前的样子:
$toRemove = array("\n");
$finalString = str_replace($toRemove, "", $s);
如您所见,我的s
字符串中的每一行在\n
它们之间都包含两行。我想搜索我的字符串并且只替换每个 SECOND\n
以便我的字符串最终成为:
question1,answer1,answer2,answer3,answer4
question2,answer1,answer2,answer3,answer4
question3,answer1,answer2,answer3,answer4
这可能吗?如果是这样,我该怎么做?