在esc_html__中添加换行符

时间:2021-12-17 作者:user193310

我想在的输出中添加换行符esc_html__ WordPress功能。原始代码为:

echo "<span class=\'gp-success\'>" . esc_html__( \'We have just sent you an email with instructions to reset your password. If you do not receive a reset email or password email please look in your spam folder.\', \'socialize\' ) . "</span>";
它输出:

We have just sent you an email with instructions to reset your password. br If you do not receive a reset email or password email please look in your spam folder.
我希望它是这样的:

We have just sent you an email with instructions to reset your password. 
If you do not receive a reset email or password email please look in your spam folder.
其中第二行:If you do not receive a reset email or password email please look in your spam folder. 必须为粗体和红色

1 个回复
SO网友:Buttered_Toast

这只是使用sprintf的一种方法

echo "<span class=\'gp-success\'>" . sprintf(esc_html__(\'We have just sent you an email with instructions to reset your password.%sIf you do not receive a reset email or password email please look in your spam folder.\', \'socialize\'), \'<br>\') . "</span>";
请注意%s 在字符串中,这是一个;占位符“;对于正在传递给sprintf的第二个和以后的参数。

另请注意,在php中使用它更好\' 而不是" 对于纯字符串," 还检查了字符串中的变量,因此需要更多资源,如果可以,如果只想输出字符串,请使用\'.

相关推荐