MyBB Community Forums

Full Version: New Lines inCustom Thread Insert
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys

Im inserting a thread using a custom script that's OUTSIDE the forum. I got the code from the mybb forums


require_once "forum/inc/datahandlers/post.php";		
// our new thread in an array
$subject = $_POST['subject'];
$message = $_POST['message'];
$message = nl2br($message);
$thread = array(
    "fid" => 54,
    "prefix" => 0,
    "subject" => $subject,
    "icon" => 0,
    "uid" => $uid,
    "username" => $username,
    "dateline" => TIME_NOW,
    "message" => $message,
    "ipaddress" => get_ip(),
    "posthash" => md5($uid.random_str())
);

// create the PostDataHandler
$posthandler = new PostDataHandler("insert");
$posthandler->action = "thread";
$posthandler->set_data($thread);

// validate the thread
if($posthandler->validate_thread())
{
    // insert it into the database
    $posthandler->insert_thread();
}

It works fine and inserts the new thread and post.

However, with "new lines" its shows in the post as "\r\n\r\n"

Even though im adding "nl2br()" ... it doesnt seem to be changing the new lines into <br>.

Am i doing something wrong? Or is there some other function that i need to pass $message through to get it to parse the message etc?

Any help? Much appreciated!