PHP fgets () function and FGETSS () function usage instructions

Source: Internet
Author: User
fgets-reading a line from the file pointer

Description

String fgets (Resource $handle [, int $length])

Reads a row from the file pointer.

Parameters

The handle file pointer must be valid and must point to a file that was successfully opened by fopen () or Fsockopen () (and not yet closed by fclose ()).

Length reads a row from the file pointed to by handle and returns a string of up to length-1 bytes in length. Stop after encountering a newline character (included in the return value), EOF, or having read the length-1 byte (see first the case). If length is not specified, the default is 1 K, or 1024 bytes.

Note:

starting with PHP 4.3, ignoring the length of the line is assumed to be 1024, and the data continues to be read from the stream until the end of the line. If most of the rows in the file are larger than 8KB, specifying the length of the largest row in the script is more efficient with resources.

return value

Returns a string after reading the length-1 byte from the file pointed to by the pointer handle. Returns FALSE if there is no more data in the file pointer.

Returns False when an error occurs.

Fgets () Function example, read the file row by line, the code is as follows

<?php$handle  = @ fopen ("/tmp/inputfile.txt",  "R"), if ($handle) {while    ($buffer  =  fgets ($ Handle,  4096)) (!==  false) {        echo  $buffer;    }    if (! feof ($handle)) {        echo  "error:unexpected fgets () fail\n";    }     Fclose ($handle);}? >

Getss-reads a row from the file pointer and filters out HTML tags

Description

String Fgetss (Resource $handle [, int $length [, String $allowable _tags]])

As with Fgets (), only FGETSS () attempts to remove any HTML and PHP markup from the text being read.

Parameters

The handle file pointer must be valid and must point to a file that was successfully opened by fopen () or Fsockopen () (and not yet closed by fclose ()).

Length to retrieve the data of that size.

Allowable_tags can use the optional third parameter to specify which tags are not removed.

return value

Read Length-1 bytes of characters from a file pointed to by handle, and filter all HTML and PHP code.

GETSS () Function example, one line reads a PHP file, the code is as follows

<?php$str  = <<<EOD

Output Result:

welcome! Today is the  . Text outside of the HTML block.

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.