Fgetss BUG and correction _ PHP Tutorial

Source: Internet
Author: User
Fgetss BUG and correction. * Author: Zhu Jiang zhu_jiang@263.net graduated from Beijing Institute of Technology, well, don't say it, it is not let me proud of the local php4.X system provided by fgetss /*
Author: Zhujiang zhu_jiang@263.net
Graduated from Beijing Institute of Technology
Work well, huh, don't say it, it's a place that doesn't make me proud.

The fgetss () function provided by the php4.X system is incomplete. HTML tags cannot be filtered out for analysis.
Some situations are ignored. the following code is a self-made cannon in the development process.

The following code can be used to study the fgetss BUG:
$ Fp = fopen ("index.html", "r ");
While (! Feof ($ fp ))
{
$ Ms = fgetss ($ fp );
Printf ($ ms );
}
Fclose ($ fp );

Free
*/
Function mygets ($ myFile)
{
// While (! Feof ($ myFile ))
//{
$ Myline = fgets ($ myFile, 255 );

$ Big = strlen (strstr ($ myline, "> "));
$ Small = strlen (strstr ($ myline, "<"));
If ($ big> $ small) // This sentence is very important. it is useful if there is a line change in the HTML code.
{// If the first line appears is> instead <时有用
$ Myline = strstr ($ myline, "> ");
$ Myline = substr ($ myline, 1 );
}

$ Len = strlen ($ myline );
$ Startskip = false;
$ Outstring = ""; // important!

For ($ I = 1; $ I <= $ len; $ I ++) // remove all HTML code
{
$ A = substr ($ myline, $ i-1, 1 );
Switch ($)
{
Case "<":
$ Startskip = true;

// $ Myline = substr ($ myline, "> ");
// $ Myline = strstr ($ myline, 1 );
Break;
Case "> ":
// $ Myline = substr ($ myline, 1 );
$ Startskip = false;
Break;
Default:
}
If (! $ Startskip & $! = ">") $ Outstring = $ outstring. $;
}
$ Outstring = str_replace ("", "", $ outstring );
// Of course, if you do not want to add anything starting with "&", this is just a filter.
$ Outstring = str_replace ("", "", $ outstring );
$ Outstring = str_replace ("", "", $ outstring); // double quotation marks contain spaces
$ Outstring = str_replace ("", "", $ outstring );
Return $ outstring;
//}
}?>

Author: Zhu Jiang zhu_jiang@263.net graduated from Beijing Institute of Technology, well, don't say it, that is not let me proud of the local php4.X system provided by the fgetss...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.