我在使用 MySQL 中的数据显示 HTML 时遇到问题。
我使用tinyMCE,内容将保存为HTML格式。
当我想在浏览器上显示它时,它会正确显示。
但是当我尝试限制 400 个字符时无法正常工作
假设此代码为我要显示的 MySQL 内容:
<div class="someclass" >
this is content from MySQL
</div>
如果限制在20个字符,就没有结尾</div>
你可以想象如果没有那个会发生什么</div>
最佳答案
如果我理解正确的话......
可以使用php函数来限制输出
// will display only the first 100 chars
$text = substr($desc,0,100);
编辑:
保留 HTML 输出
http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/
关于mysql - 显示 html 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7371710/