Reputation: 8075
I am using ckEditor as a BBCode editor and having to do a bit of deeper work than just installing some plugins.
When saving to the database, in the field i will have e.g.
1
2
3
Yet when it is echo'd out it is
123
I need help converting those line breaks in the database, and either putting each line into a
tag or created something out of the line breaks.
I am using this function to convert other BBCodes into html just cant figure out this.
function basicbbcode($text) {
$text = str_replace("[b]", "<b>", "$text");
$text = str_replace("[/b]", "</b>", "$text");
return $text;
}
The other option i see is to convert the line breaks to
etc when inputting to the DB.
Upvotes: 0
Views: 55
Reputation: 2604
Let the PHP engine do the work for you with new lines, as it will detect what newline characters to replace automatically.
$text = nl2br($text);
All done.
Upvotes: 2
Reputation: 133
Look for the line breaks which are going to be \n, \r or \n\r:
$text = str_replace("\n", "<br/>", "$text");
$text = str_replace("\r", "<br/>", "$text");
Upvotes: 0