开发者

replace char with line break

开发者 https://www.devze.com 2023-02-14 13:17 出处:网络
I have tried several solutions to replace a , with aeither <br /> or \\n\\r To n开发者_Python百科o avail I am left stuck and wondering if the wonderful users of SO could lend a hand.

I have tried several solutions to replace a , with aeither <br /> or \n\r

To n开发者_Python百科o 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


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']));

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号