开发者

replace char with line break

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜