Convert new lines in xf_post.message to HTML

fishb6nes

Member
I'm displaying a news feed on my home page by retrieving the latest threads in a certain set of nodes from the db and subsequently retrieving the messages belonging to their OPs. The messages appear to be stored with new lines and all in the db, but as soon as I put them in a paragraph it displays as one large continues string.

Live demo: http://seventhsin.gg
Code that retrieves the message:
Code:
$sql = "SELECT message FROM xf_post WHERE post_id = " . $post_id . ";";
$result = $db->query($sql);
if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $message = $row['message'];
    $result->free();
}

Am I missing a certain character I should call str_replace('char', '<br />', $message); on or am I losing the new lines all together via the way I'm retrieving the data?
 
You'll need to send the post through the BBCode-Parser in order to render it with new lines and urls working.
 
Is there no way to detect the new lines at all? The URLs aren't the problem, I just haven't gotten round to them yet. But from the looks of it I got nothing to work with to parse the new lines myself.
 
You can render the parser with this code. It is untested though, but it must work.

PHP:
$parser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false));

$message = $parser->render($message);
 
Top Bottom