I am building a website in Hindi language. I was given a Database containing rows of title and body. I created a node for each row using this code :

$query = db_select('hindi', 'n')
      ->fields('n', array('title','body'))

foreach($query as $item) {
    $title = $item->title;
    $body = $item->body_value;
    $values = array(
        'type' => 'article',
        'uid' => 1,
        'status' => 1,
        'comment' => 0,
        'promote' => 0,
        'language'  => 'hi'
    $entity = entity_create ('node', $values);
    $ewrapper = entity_metadata_wrapper('node', $entity);
    $ewrapper->field_body->set(array('value' => $body,'format'=>'full_html'));

The nodes are display very well in the node view page, like this

enter image description here

But Ckeditor doesn't perform the text formats (line breaks and ...). Like this

enter image description here

What is the problem?

More information

This is the result of Firebug when inspecting the Body value of the CKEditor

enter image description here

  • 2
    did you try to see source of this data? ( I mean source of ckeditor ), is there html tags like <br> exists ?
    – Yuseferi
    Sep 29, 2016 at 7:12
  • @zhilevan There is no <br/> tag in CKEditor
    – M a m a D
    Sep 29, 2016 at 7:20
  • No, just push source button of ckeditor on top left,
    – Yuseferi
    Sep 29, 2016 at 7:32
  • @zhilevan I tried that. All the text is in a single <p>, As the Firebug shows
    – M a m a D
    Sep 29, 2016 at 8:41
  • do you see any <br> in inspecting body rendered field in node view ?
    – Yuseferi
    Sep 29, 2016 at 8:46

1 Answer 1


According to my experience <br> causes this problem ,my solution for this is to replace all <br> with <br /> before saving in body field

So try

$body =   str_replace("<br\s*>", "<br />",nl2br($item->body_value));
  • According to the link, is it related to the value of "Filtered HTML" text format?
    – Jimmy Ko
    Sep 29, 2016 at 9:19
  • 1
    @JimmyKo I changed it ;) this solution will work, I had the same situation before.
    – Yuseferi
    Sep 29, 2016 at 9:21
  • 1
    @zhilevan Thank you very much. I will try it and let you know the result
    – M a m a D
    Sep 29, 2016 at 9:31
  • @Drupalist you're welcome,I hope work for you
    – Yuseferi
    Sep 29, 2016 at 9:32
  • @JimmyKo do you see according to my experience worked? :)
    – Yuseferi
    Sep 29, 2016 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.