I've a MySQL database and one of the columns is 'Address' which sometimes contains more then 1 row. For instance I have the following address:
Street X, Block Y, Apartment Z, Door W
When I will get data from MySQL and echo
it I'd end up with:
Street X, Block Y, Apartment Z, Door W
How do I detect the end of row in MySQL so I can add a . <br>
?
Use nl2br function, which has following the description:
Inserts HTML line breaks before all newlines in a string
So finally the code to do your task will be as simple as
$address = nl2br($address);
I think nl2br($data)
is a good but dirty solution since it adds only <br>
I will suggest to use this expression '/[ ]+/'
to identify the special endline characters
For example
$text = trim($text);
'<youtag>' . preg_replace('/[
]+/', '</youtag><youtag>', $text) . '</youtag>';
If I'm understanding correctly, you've got a newline character in the appropriate place in the data stored in MySQL, but the newline isn't being displayed correctly when you query the table. One option is to use a MySQL query that replaces the newline character with the line break string:
SELECT REPLACE(`Address`, '
', '<br>') FROM mydatabase.mytable;