问题描述
因此,函数nl2br很方便.除了在我的网络应用程序中,我想做相反的事情,将换行符解释为新行,因为换行符将被回显为预先填充的形式.
So the function nl2br is handy. Except in my web app, I want to do the opposite, interpret line breaks as new lines, since they will be echoed into a pre-filled form.
str_replace可以使用<br />
并将其替换为我想要的任何内容,但是如果我输入\ n,它将在字面上回显一个反斜杠和一个n.仅当我在脚本的中间放置一个文字换行符并中断缩进时才有效(这样就没有尾随空格了).
str_replace can take <br />
and replace it with whatever I want, but if I put in \n, it echoes literally a backslash and an n. It only works if I put a literal line break in the middle of my script, and break the indentation (so there are no trailing space).
请参阅:
<?=str_replace('<br />','
',$foo)?>
我是否缺少转义字符?我想我尝试了所有组合...
Am I missing escape characters? I think I tried every combination...
推荐答案
您在写'\n'
吗?因为\ n仅在用双引号引起来时才能正确解释:"\n"
.
Are you writing '\n'
? Because \n will only be interpreted correctly if you surround it with double quotes: "\n"
.
关闭主题:<?=
语法是邪恶的.请不要为了团队中的其他开发人员而使用它.
Off topic: the <?=
syntax is evil. Please don't use it for the sake of the other developers on your team.
这篇关于与nl2br相反?是str_replace吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!