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.