• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Convert new lines in xf_post.message to HTML

#1
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?
 
#3
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.
 

wang

Well-known member
#5
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);