我有以下几行:
Four41dk: folds
Masuronike: folds
Four41dk is sitting out
我用str_replace替换他们的名字“Four41dk,Masuronike”为
<span class='bold'> $theirName </span: folds
<span class='bold'> $theirName </span: folds
etc...
这很有效,但问题是当名称位于字符串的末尾时,如:
Four41dk: folds
Uncalled bet (73) returned to MASUR0N1KE
Four41dk is sitting out
现在,当我更换尼克斯后,我在返回到MASURONIKE之后丢失了新行,所以输出在一行中如下:
Uncalled bet (73) returned to <span>MASUR0N1KE </span> <span> Four41dk </span> is sitting out
我该如何解决?
我想我需要这样的东西:
用名字替换姓名,但是在名称之后\ n \ n
答案 0 :(得分:0)
str_replace(...) . "<br/>";
只是HTML吗?
Four41dk: folds
Masuronike: folds
Four41dk is sitting out
在纯文本中,您希望在HTML
中将其呈现为:
<span>Four41dk</span>: folds <br/>
<span>Masuronike</span>: folds <br/>
<span>Four41dk</span> is sitting out <br/>
然后,您的PHP代码应为:
$input = "Four41dk: folds \n" .
"Masuronike: folds \n" .
"Four41dk is sitting out \n";
$output = nl2br(str_replace('Four41dk', '<span>RTM</span>', $input));
echo $output;
我为缺乏通用代码道歉,但它与op。
相吻合