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']));
精彩评论