用于删除&;nbsp并跳过一行


PHP function for removing &nbsp and skip a line

我想擦除&nbsp在Wordpress文章中,当我们跳过一行但保留"跳过一行"时。

在post.php中,我添加了以下功能:

function remove_empty_lines( $content ){
    $content = preg_replace("/ /", "'n", $content);
  return $content;
}
add_action('content_save_pre', 'remove_empty_lines');

但是不起作用,我能写什么起作用?(<br />也不起作用)。

'n不表示HTML中的新行,因此在回显结果时不会看到换行符。直接使用"<br />"作为替换,或者使用默认的nl2br() PHP函数在PHP换行之前插入HTML换行符,例如

$sample = "testing a 'n line break";
echo $sample;
// HTML output is:
"testing a  line break"
$sample2 = "testing a <br /> line break";
echo $sample2;
// HTML output is:
"testing a
 line break"
$sample3 = "testing a 'n line break";
$sample3 = nl2br($sample3);
echo $sample3;
// HTML output is:
"testing a
 line break"

HTML中的换行符通过<br ><br/>表示,而不是通过'n表示。

$content = str_replace("&nbsp;", '<br/>', $content); echo nl2br($content);