Home > php教程 > php手册 > fgetss的BUG及纠正

fgetss的BUG及纠正

WBOY
Release: 2016-06-13 10:23:25
Original
1319 people have browsed it


/*
作者:朱江 zhu_jiang@263.net
毕业于北京工业大学
工作嘛,呵呵,不说也罢,那是一个并不让我引以为荣的地方

php4.X的系统所提供的fgetss()功能不完善,不能滤干净HTML TAG,分析
其中忽略了某些情况,以下代码是本人在开发过程中自制的土炮。

关于fgetss的BUG,可用如下代码研究一下:
$fp=fopen("index.html","r");
while (! feof($fp))
{
$ms=fgetss($fp);
printf($ms);
}
fclose($fp);

版杈 :免费
*/
function mygets($myFile)
{
//while(!feof($myFile))
//{
$myline = fgets($myFile, 255);

$big=strlen(strstr($myline,">"));
$small=strlen(strstr($myline,"if($big>$small) //此句很重要,如果HTML代码中间有换行时有用
{ //如果一行中首先出现的是>而不是$myline=strstr($myline,">");
$myline=substr($myline,1);
}

$len=strlen($myline);
$startskip=false;
$outstring=""; //important!

for($i=1;$i{
$a=substr($myline,$i-1,1);
switch($a)
{
case "$startskip=true;


//$myline=substr($myline,">");
//$myline=strstr($myline,1);
break;
case ">":
//$myline=substr($myline,1);
$startskip=false;
break;
default:
}
if(!$startskip && $a!=">") $outstring=$outstring.$a;
}
$outstring=str_replace(" "," ",$outstring);
//当然,以&开头的东东如果不想要可以再加,如法炮制,这里只是过滤 
$outstring=str_replace(" ","",$outstring);
$outstring=str_replace(" ","",$outstring); //双引号内为全角空格
$outstring=str_replace(" ","",$outstring);
return $outstring;
//}
} ?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template