php - 如何从mysql中的文本字段中读取数据

标签 php mysql

如何使用 php 输出格式化的文本。我将它存储在一个字段中,将是 longtext 数据类型。我使用以下代码保存数据:

<?php 
if(!empty($_POST)){
    $code = mysql_real_escape_string($_POST['x']);
    $db->query("INSERT INTO tbl_codes SET code='$code'");
}
?>

但是当我尝试检索它时:

<?php echo htmlentities($yo); ?>

它还没有格式化。如果我不使用 htmlentities 函数,我将看不到任何输出。请帮忙

最佳答案

作为doc说,htmlentities将转换像 ' < 这样的字符' 和 ' > '在'&lt; ' 和 ' &gt; ' 因此 html 标签将无效。例如,如果您有这样的粗体文本:

<b>example</b>

它将转换为:

&lt;b&gt;example&lt;/b&gt;

由于您在上一条评论中写道您只需要 <pre>标签,可以考虑使用strip_tags的可能性喜欢:

$cleanOutput = strip_tags($yo, '<pre>');

关于php - 如何从mysql中的文本字段中读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7860007/

相关文章:

php - 从 PHP 解析 JSON

php - 我应该使用html_entity_decode来转义Google Analytics(分析)自定义变量吗?

php - CodeIgniter 向 CSV 添加字段

php - 从表中获取多个值

php - mysql 查询输出显示计数的数据表

mysql - 授予本地主机所有权限

mysql - MySql建表出错 : check the manual that corresponds to your MySQL server version for the right syntax to use near ')'

mysql - 错误 2002 (HY000) : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) occured

php - mootools单选按钮问题

php - 将当前日期插入表中