简体   繁体   中英

How to return formatted text from database into TinyMCE

I have just a problem. I would like to have formatted text from database in my TinyMCE.

In the database I have code that looks like this:

 <p style="text-align: justify;"><strong>Zdrav&iacute;m</strong></p>

And my script is here:

 <script type="text/javascript">
 // Initialization TinyMCE (JS)
 tinyMCE.init({ ... });

 function loadText(text) {

    var editor = window.parent.tinyMCE.activeEditor;
    editor.setContent(text);
 }
 </script>

 // PHP
 $q = mysql_query("SELECT * FROM article WHERE id = ".$_GET['id'].""); 
 while ($z = mysql_fetch_array($q)) { 
     $text = html_special_chars($z['content']);
 }

And if I try something like this:

<body onload = "loadText('hello');">

That does works and content is loading into TinyMCE (without formatted)!

But if I try something like this:

<body onload = "loadText(' <? echo $text; ?> ');">

That doesn't work!

What is going wrong? I think, that problem will maybe in quotes and apostrophes.

Other ideas and suggestions?

Why don't you put your database text right into the element you use for the tinymce on page creation. Lika a textarea. This would save some trouble:

<textarea id="my_editor"><? echo $text; ?></textarea>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM