Php str_替换解码功能不工作

Php str_替换解码功能不工作,php,Php,由于某种原因,该函数的搜索和替换部分不起作用。我的语法错了吗 function display($data) { $new = str_replace('<br />',"\n",$data); $newer = htmlspecialchars($new); $search = array('&lt;b&gt;', '&lt;/b&gt;', '&lt;i&gt;', '&lt;/i&gt;', '&

由于某种原因,该函数的搜索和替换部分不起作用。我的语法错了吗

function display($data) {

$new = str_replace('<br />',"\n",$data);
$newer = htmlspecialchars($new);
    $search  = array('&lt;b&gt;', '&lt;/b&gt;', '&lt;i&gt;', '&lt;/i&gt;', '&lt;u&gt;', '&lt;/u&gt;', '\r\n');
    $replace = array('<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<br />');

  $newest = str_replace($replace, $search, $newer);

  return $newest;
}
功能显示($data){
$new=str_replace(“
”、“\n”、$data); $newer=htmlspecialchars($new); $search=array('b'、'/b'、'i'、'/i'、'u'、'/u'、'\r\n'); $replace=数组(“”、“”、“”、“”、“”、“”、“
”); $newest=str_replace($replace,$search,$newer); 返回$最新版本; }
用以下方法尝试:

function display($data) {

$new = str_replace('<br />',"\n",$data);
$newer = htmlspecialchars($new);
$replace = array('<b>' => '&lt;b&gt;', '</b>' => '&lt;/b&gt;', '<i>' => '&lt;i&gt;', '</i>'=> '&lt;/i&gt;', '<u>' => '&lt;u&gt;', '</u>' => '&lt;/u&gt;', '<br />' => '\r\n');
$newest = $newer;

foreach($replace as $rep => $find){
     $newest = str_replace($rep , $find, $newest);
}
  return $newest;
}
功能显示($data){
$new=str_replace(“
”、“\n”、$data); $newer=htmlspecialchars($new); $replace=array(“”=>'b'、“”=>'/b'、“”=>'i'、“”=>'/i'、“”=>'u'、“”=>'/u'、“”
'=>'=>'\r\n'); $newest=$newer; foreach($rep=>$find替换为$rep){ $latest=str\u replace($rep,$find,$latest); } 返回$最新版本; }
开始时,
$data
的值是什么?看看参数顺序:手册比这更快更简单。哇!这到底是怎么颠倒过来的??这是对我之前创建的复制粘贴函数的修改,效果很好。我不知道为什么它们会从原来的样子颠倒过来。真奇怪!为什么不使用
nl2br()
而不是
stru replace()