fgetss的BUG及糾正_PHP教程

來源:互聯網
上載者:User
/*
作者:朱江 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<=$len;$i++) //去掉所有HTML代碼
{
$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;
//}
} ?>

http://www.bkjia.com/PHPjc/532241.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532241.htmlTechArticle/* 作者:朱江 zhu_jiang@263.net 畢業於北京工業大學 工作嘛,呵呵,不說也罷,那是一個並不讓我引以為榮的地方 php4.X的系統所提供的fgetss...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.