这段php代码怎么过滤HTML!望指教

来源:百度知道 编辑:UC知道 时间:2024/05/18 02:27:59
<form method=get action=test.php ><input type=text name=q size=25 value="" input type="submit" value="提交" >

<?php
$time_start = getmicrotime();
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$data = explode("\n", str_replace("\r", '', file_get_contents('1.txt')));
$breplace=array("<", ">"," ");
$areplace=array("","","|");
$keyword = str_replace($breplace,$areplace,$_GET["q"]);//字符替换
foreach($data as $thisdata) {
if(preg_match('/'.$keyword.'/i', $thisdata) and ($keyword != "")) {
echo $thisdata."\r\n<br>";
}
}
?>

你的代码是错误的:

还是帮你解释一下:

getmicrotime() :对脚本的运行计时 与脚本过滤html无关!

//在$_GET["q"]中如果找到$breplace就替换成$areplace;
//在这里是将提交的字符中的"<", ">"," "(空格)
//分别替换成:空,空,|;
preg_match('/'.$keyword.'/i', $thisdata)
//在$thisdata中查找是否有与$keyword相同的字段!
//如果有就echo echo $thisdata;
'/'.$keyword.'/i'//正则表达式 意思是不区分大小写的匹配$keyword

因为你的1.txt内容不清楚所以也不知道你要干什么!