1. 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

Discussion in 'XenForo Development Discussions' started by fishb6nes, Jan 10, 2016.

  1. fishb6nes

    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:
    $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'];
    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?
  2. katsulynx

    katsulynx Well-Known Member

    You'll need to send the post through the BBCode-Parser in order to render it with new lines and urls working.
  3. fishb6nes

    fishb6nes Member

    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.
  4. katsulynx

    katsulynx Well-Known Member

    Just instanciate the parser and use it.
  5. wang

    wang Well-Known Member

    You can render the parser with this code. It is untested though, but it must work.

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

    $message $parser->render($message);

Share This Page