Download Baidu Ueditor Editor and configure the method share
In fact, it is very simple, but to read the data need to use Htmlspecialchars_decode ($STR), the function escaped, otherwise read the content a little bit of a problem, see the details
Because of typesetting requirements, many times we need to embed a rich text editor to output text content with HTML tags. Because I recently made a background management system, asked to edit the text content, let it output with HTML tag text to the server, the client sent the request to get the server's tagged text. I'm using a ueditor,
1. First we go here www.jb51.net/codes/56667.html download the PHP version UTF version.
Put it in the public directory.
2. When we use the Rich Text editor, we usually add the textarea to the form in the view,
<form> <p><textarea name= "Intro_detail" id= "Intro_detail" cols= "ten" rows= "></textarea" > </p></form>
3. At the end of the HTML add script to configure the text box initial value, where public is the path I configured in config
<script type= "Text/javascript" src= "public/ueditor/ueditor.config.js" ></script><script type= "text/ JavaScript "src=" Public/ueditor/ueditor.all.min.js "></script><!--recommended to be added manually in the language, Avoid in IE sometimes because the load language failure causes the editor to fail--><!--the language files loaded here will overwrite the language type you added in the configuration item, such as the English you configured in the configuration item, the Chinese in the load, and the last Chinese-->< Script type= "Text/javascript" src= "public/ueditor/lang/zh-cn/zh-cn.js" ></script><script type= "text/ JavaScript > ue.geteditor (' Intro_detail ', { //intro_detail is the ID of the textarea to be edited initialframewidth:418 , //Initialize width initialframeheight:500, //Initialize height });</script>
4. Usually when we add a button in the form will default to the data in the form of all submitted, but my project is also involved in the picture upload problem, I am using the Ajax asynchronous submission, then the question, we can pass the JQ ("#intro_detail"). val () value to get the value to be submitted, the answer is no, my method is to add a hidden input under the textarea, I use the method provided by the Ueditor to get the value inside the input, let it with the table as a single submission in the past, the controller can be passed through the _post (' form's name '), as follows:
<p > <textarea name= "Intro_detail" id= "Intro_detail" cols= "ten" rows= "></textarea></p" > <input type= "text" style= "Display:none" id= "Intro_detail1" name= "Intro_detail1" >
Ajax submissions,
The code is as follows:
$ ("#intro_detail1"). Val ("'" +ue.geteditor (' Intro_detail '). GetContent () + "'");
The text box entered with the label of the single quotation mark together, stored in the input inside a concurrent past, as to why the single quotation mark, otherwise, will automatically filter out the label, we take the data out when the single quote processing off.
$.ajax ({ type: "POST", URL: "<{:u (' admin/gamemanager/game/modgame ')}>", dataType: ' JSON ', Processdata:false, Contenttype:false, cache:false, data:formdata, success:function (r) { if ( r.success) { alert (' Edit succeeded '); Window.location.reload ();//Refresh the $ (' #user_dialog ') once again. Modal (' hide '); } else{ alert ("parameter Error");}} );
5. Inside the controller, you can use $_post (' name ' of the form ') to get the data and write it into the database.
$db = M (' game '); $data = $db->create (I (' post. ')); $data [' intro_detail '] = $_post[' intro_detail1 '); $db->add ($data);
6. When we take the data to the view, we can get rid of the single quotation mark.
foreach ($result as $key = $value) { $result [$key] [' Intro_detail ']=str_replace ("'", "", $result [$key] [' Intro_ Detail ']);//filter single quotes } $this->assign (' game_list ', $result); $this->display (");
$result is the database content I found in the SQL statement, and Intro_detail is the text content that is stored in the database with tags and single quotes
$user = M (' game '); $result = $user->field ();
7. In fact, it is not difficult, I also provide you with the next idea, you can discuss a lot, I am also small white.