字符串与HTML相互转换

一 代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>字符串与HTML相互转换</title>
<style type="text/css">
<!--
.STYLE3 {
	font-size: 13px;
	color: #993300;
}
.STYLE4 {
	font-size: 20px;
	color: #993300;
	font-family: "新宋体";
	font-weight: bold;
}
.STYLE5 {font-size: 13px; color: #993300; font-weight: bold; }
-->
</style>
</head>
<body>
<table width="550" height="218" border="1" cellpadding="2" cellspacing="1" bordercolor="#33CC33" bgcolor="#CCFF33">
  <tr>
    <td height="38" colspan="2" align="center"><span class="STYLE4">字符串转换成HTML</span></td>
  </tr>
  <tr>
    <td width="120" align="right" class="STYLE5">转换的结果为:</td>
    <td width="413" height="100" align="left"><span class="STYLE3">
    <?php 
	$str='<table width="300" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#993300">
	  <tr>
		<td align="center" bgcolor="#FFFFFF" class="STYLE3">做人做事</td>
	  </tr>
	  <tr>
		<td align="center" bgcolor="#FFFFFF" class="STYLE3">认认真真做事,坦坦荡荡做人!</td>
	  </tr>
	</table>';
	echo htmlentities($str,ENT_QUOTES,"GB2312")."<br>";
	?>
    </span>
	</td>
  </tr>
  <tr>
    <td align="right" class="STYLE5">不转换输出结果:</td>
    <td height="80" align="center"><span class="STYLE3"><?php echo $str; ?></span></td>
  </tr>
</table>
</body>
</html>

 

二 运行结果
 
三 说明
htmlentities()函数将所有的字符串都转换为HTML字符。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值