我想擦除 在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(" ", '<br/>', $content);
echo nl2br($content);