1

Im trying to get HTML from my MySQL table inserted into my TinyMCE editor. But I have serious trouble setting up the PHP string into Javascript.

when I just try to insert it like this:

tinymce.activeEditor.setContent("'<? echo $description; ?>'", {format: 'raw'});

It has trouble with the single quotes and the double quotes in the $description variable. I get unidentified id's in my string because the string gets cut off due to the single and double quotes that are located in the string.

How can I insert this into TinyMCE, which ultimately comes down to how to make a HTML string without cutting of early?

1
  • Escape the characters in the string. There's plenty of PHP functions for doing that such as htmlspecialchars() and the like. Commented Dec 6, 2017 at 12:27

1 Answer 1

1

You can simply replace those characters:

tinymce.activeEditor.setContent("'<? echo str_replace(array('"', "'"), array('\"', "\'"), $description); ?>'", {format: 'raw'});
Sign up to request clarification or add additional context in comments.

1 Comment

No this doesnt work because then the code doesn't get identified by TinyMCE and I get source code straight into it. I need to make sure TinyMCE id's the html code.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.