<html>
<head>
<title>HTML 表单</title>
</head>
<body>
<form action="" method="POST">
请输入一个字符串:
<input type="text" size="30" name="str" value="">
<input type="submit" name="submit" value="提交"><br/>
</form>
<?php
if(isset($_POST['submit'])) {
//this a "test",5.3.8不自动加斜杠,我测试时是这样的
echo "原型输出:".$_POST['str']."<br/>";
echo "转换实例:".htmlspecialchars($_POST['str'])."<br/>";
echo "删除斜线:".stripslashes($_POST['str'])."<br/>";
echo "删除斜线和转换实体:".html2Text($_POST['str'])."<br/>";
}
function html2Text($input) {
return htmlspecialchars(stripslashes($input));
}
?>
<?php
$str = "<font color='red' size=7>Linux</font><i>Apache</i><u>MySQL</u><b>PHP</b>";
echo strip_tags($str);//删除全部HTML标签
echo "<br/>";
echo strip_tags($str,"<font>");//第二个参数,保留的标签
echo "<br/>";
echo strip_tags($str,"<b><u><i>");
?>
</body>
</html>
<head>
<title>HTML 表单</title>
</head>
<body>
<form action="" method="POST">
请输入一个字符串:
<input type="text" size="30" name="str" value="">
<input type="submit" name="submit" value="提交"><br/>
</form>
<?php
if(isset($_POST['submit'])) {
//this a "test",5.3.8不自动加斜杠,我测试时是这样的
echo "原型输出:".$_POST['str']."<br/>";
echo "转换实例:".htmlspecialchars($_POST['str'])."<br/>";
echo "删除斜线:".stripslashes($_POST['str'])."<br/>";
echo "删除斜线和转换实体:".html2Text($_POST['str'])."<br/>";
}
function html2Text($input) {
return htmlspecialchars(stripslashes($input));
}
?>
<?php
$str = "<font color='red' size=7>Linux</font><i>Apache</i><u>MySQL</u><b>PHP</b>";
echo strip_tags($str);//删除全部HTML标签
echo "<br/>";
echo strip_tags($str,"<font>");//第二个参数,保留的标签
echo "<br/>";
echo strip_tags($str,"<b><u><i>");
?>
</body>
</html>