如何阻止html TEXTAREA解码html实体 [英] How to stop an html TEXTAREA from decoding html entities

查看:156
本文介绍了如何阻止html TEXTAREA解码html实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题:

在数据库中,我有一个字符<< / p>

 & lt; div 

每当它打印到html textarea标记,页面的源代码将& gt; 显示为>



如何停止解码?

解决方案

在PHP中,这可以通过使用ヶ辆()。下面的例子。

 <?php 
$ content =这个字符串包含TM符号:& trade; ;
打印< textarea>。 htmlentities($ content)。< / textarea>;
?>

如果没有htmlentities(),textarea会解释并显示TM符号(™)而不是 & trade;。



http://php.net/manual/en/function.htmlentities.php

I have a strange problem:

In the database, I have a literal ampersand lt semicolon:

&lt;div  

whenever its printed into a html textarea tag, the source code of the page shows the &gt; as >.

How do I stop this decoding?

解决方案

In PHP, this can be done using htmlentities(). Example below.

<?php
  $content = "This string contains the TM symbol: &trade;";
  print "<textarea>". htmlentities($content) ."</textarea>";
?>

Without htmlentities(), the textarea would interpret and display the TM symbol (™) instead of "&trade;".

http://php.net/manual/en/function.htmlentities.php

这篇关于如何阻止html TEXTAREA解码html实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆