Skip to content
Advertisement

Can’t retrieve in correct form data from SQL in TinyMCE

I want to create an editor with TinyMCE and I have an error when I want to add content from SQL.

The function inside tinymce.init is:

setup: function (editor) {
  editor.on('init', function (e) {
    editor.setContent('<?php print_r($contract->anexa_la_contract);?>');
  });
}

It needs to load the content. Instead, it gives this error in the console:

Uncaught SyntaxError: ” string literal contains an unescaped line break

This is the result from the error:

editor.on('init', function (e) {
  editor.setContent('<ul>
    <li>sda</li>
    <li>sda</li>
    <li>sda</li>
    <li>ds</li>
  </ul>');
  });
}

Any advice on how I should fix it?

Advertisement

Answer

You can remove the line breaks, I don’t think you really need them

editor.setContent('<?php echo preg_replace("/[nr|rn|r|n]/m", "", $contract->anexa_la_contract); ?>');

more info and example you can find in

PHP preg_replace replacing line break

preg_replace() and n in a string

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement