user3242513
user3242513

Reputation: 37

Why my text appears like this?

In my addpost form i put my text in paragraphs like this:

Morbitincidunt maurisque eros molest nunc anteget sed vel lacus mus semper.

Anterdumnullam interdum eros dui urna consequam ac nisl nullam ligula vestassa.

Condimentumfelis et amet tellent quisquet a leo lacus nec augue accumsan sagittislaorem dolor sum at urna.

But on my website its appears like this:

Morbitincidunt maurisque eros molest nunc anteget sed vel lacus mus semper. Anterdumnullam interdum eros dui urna consequam ac nisl nullam ligula vestassa. Condimentumfelis et amet tellent quisquet a leo lacus nec augue accumsan sagittislaorem dolor sum at urna.

Someone knows how to fix this problem ? I use "ckeditor" in my "addposts" form. In the table of my DB the text appears like in the 1st example wich i gave. Only the problem is how it's appears in my website.

Upvotes: 0

Views: 78

Answers (2)

youser
youser

Reputation: 11

You can try allow br element in config:

config.extraAllowedContent = 'p br';

or replace br tag when pasting text:

editor.on( 'paste', function( evt ) {
        var data = evt.data.dataValue;
        data = data.replace( /<br \/>|<br>|<br\/>/g, '</p><p>' );
        evt.data.dataValue = data;
    });

bun only if config.enterMode was NOT changed to CKEDITOR.ENTER_BR;

Upvotes: 0

ITChristian
ITChristian

Reputation: 11271

  1. The simplest way is to use nl2br().

  2. If you don't want to use <br/>, and if you want to use <p></p> tags, you can use this function:

     function convert ($text) {
       $text = trim($text);
       return '<p>' . preg_replace('/[\r\n]+/', '</p><p>', $text) . '</p>';
     }
    

Hope this helps!

Upvotes: 2

Related Questions