用换行符替换字符
我尝试了几种解决方案来替换 ,
与
或 \n\r
但无济于事,我被困住了并想知道 SO 的优秀用户是否可以伸出援手。
$row['address'] = 'Unit A, 64 Alert Square, London, E16';
echo "Address: ". nl2br(str_replace(',',' \r\n ', $row['address']));
结果:Unit A \r\n 64 \r\n Alert \r\n Square \r\n London \r\n E16
需要,嗯,期望的效果:
Unit A
64 Alert Square
London
E16
I have tried several solutions to replace a ,
with aeither <br />
or \n\r
To no avail I am left stuck and wondering if the wonderful users of SO could lend a hand.
$row['address'] = 'Unit A, 64 Alert Square, London, E16';
echo "Address: ". nl2br(str_replace(',',' \r\n ', $row['address']));
result: Unit A \r\n 64 \r\n Alert \r\n Square \r\n London \r\n E16
needed, well, desired effect:
Unit A
64 Alert Square
London
E16
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像
\r
和\n
这样的字符转义需要使用双引号或heredocs才能被PHP理解,例如:echo "Address: "。 nl2br(str_replace(',', "\n", $row['address']));
Character escapes like
\r
and\n
need to be double quotes or heredocs to be understood by PHP, e.g.:echo "Address: ". nl2br(str_replace(',', "\n", $row['address']));