删除字符串周围的第一个'n'实例



嗨,我有以下情况,我有标签围绕我的内容和以下输入

[hello]
Text here
[/hello]
[hello]
Text here 2
[/hello]

输出为

[hello]nnText herenn[/hello]nn[hello]nnText here 2nn[/hello]

期望的输出应该是

[hello]nText heren[/hello][hello]nText here 2n[/hello]

PS:谢谢你的回答,但是由于是用户输入,所以有可能出现空格[hello] n

是否有一种方法使用php,修剪周围的开始标签([hello])和结束标签([/hello])的第一个n ?由于

这很简单,换句话说,您要将nn替换为n

$str = "[hello]nnText herenn[/hello]nn[hello]nnText here 2nn[/hello]";
echo str_replace("nn", "n", $str);

它将输出

[hello]
Text here
[/hello]
[hello]
Text here 2
[/hello]

很简单,试试这个:

$str = "[hello]nnText herenn[/hello]nn[hello]nnText here 2nn[/hello]";
echo str_replace("[hello]n","[hello]", str_replace("n[/hello]","[/hello]",$str));

最新更新