php 转换HTML代码函数示例

前端之家收集整理的这篇文章主要介绍了php 转换HTML代码函数示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
经测试代码如下:
  1. /**
  2. * 转换HTML代码函数
  3. *
  4. * @param unknown_type $content
  5. * @param unknown_type $wrap 是否换行
  6. */
  7. function htmlClean($content,$wrap = true) {
  8. $content = htmlspecialchars($content);
  9. if ($wrap) {
  10. $content = str_replace("\n",'<br />',$content);
  11. }
  12. $content = str_replace(' ','&nbsp;&nbsp;',$content);
  13. $content = str_replace("\t",'&nbsp;&nbsp;&nbsp;&nbsp;',$content);
  14. return $content;
  15. }
  16. /*** 来自编程之家 jb51.cc(jb51.cc) ***/

猜你在找的PHP相关文章