简体   繁体   中英

how to handle data from text editors store in database and later display

I use TinyMce for project. when i get the text from the user, i do the following with PHP

  • to handle the html inputs i use htmlspecialchars() mysql_real_escape_string() functions available on php to make it ready for storage in database.
  • i then store it in the database.

Now how do i safely insert, retrieve and display html data. One big challenge is to get only the text, without the html and make it available as the Meta description of the page.

In a nutshell i want to

  • Get data from text editor
  • format and store in database
  • retrieve from database
  • get clean version without html tags
  • get html version and display on page

You can use strip_tags()

Refer: http://php.net/manual/en/function.strip-tags.php

you can use html2text class.

<?php
require_once(‘class.html2text.inc’);
$html = ‘Sample string with HTML code in it’;
$h2t =& new html2text($html);
$text = $h2t->get_text();
$h2t->print_text();
?>

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