0

我有这些行:

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

现在,当我更换刻痕时,我在 RETURNED TO MASURONIKE 后丢失了新行,因此输出在一行中,例如:

Uncalled bet (73) returned to <span>MASUR0N1KE </span> <span> Four41dk </span> is sitting out

请问我该如何解决?

我想我需要类似的东西:

用 Span 替换 NAME 的名称,但当有 \n 之后,请保留它

4

1 回答 1

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 配合得很好。

于 2013-08-28T10:02:03.860 回答