This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
uphp:functions:fgets [2017/03/28 20:09] jeff |
uphp:functions:fgets [2021/09/13 05:57] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
======fgets====== | ======fgets====== | ||
+ | |||
< | < | ||
- | Return a single line from a file or stream, with optional size limit | + | Return a single line from a file, stream |
====Description==== | ====Description==== | ||
- | <well size=" | + | |
- | <span style=" | + | <well size=" |
- | < | + | <span style=" |
- | <span style=" | + | <span style=" |
- | <span style=" | + | <span style=" |
- | <span style=" | + | <span style=" |
- | <span style=" | + | <span style=" |
- | <span style=" | + | <span style=" |
- | <span style=" | + | <span style=" |
+ | <span style=" | ||
</ | </ | ||
- | This function works with different resource types. If no size is specified, it will keep reading from the file or stream until it reaches the end of the line (or the end of the file). For sockets and streams it will return characters until a line feed (LF) or carriage return (CR) is reached (it will wait until an entire line is received). If the optional size is specified and the line is longer than this size, the function will return only the number of characters specified. | + | This function works with different resource types. If no size is specified, it will keep reading from the file, stream |
+ | |||
+ | **Note:** The maximum length of a returned string in [[hardware: | ||
====Parameters==== | ====Parameters==== | ||
- | < | ||
- | < | + | <html><b>< |
+ | |||
+ | < | ||
====Return Values==== | ====Return Values==== | ||
- | | + | |
- | * Empty string if there is no data on the line | + | |
- | * -1 for error | + | * Empty < |
+ | * < | ||
====Example==== | ====Example==== | ||
- | **Open a TCP connection to google.com and print the header for a search for the word ' | + | |
+ | ===Open a TCP connection to google.com and print the header for a search for the word ' | ||
<code php> | <code php> | ||
Line 53: | Line 60: | ||
</ | </ | ||
- | ====See Also==== | + | ====Also |
- | [[fread()]] - Return a specified number of bytes from a file or stream | + | |
- | [[fwrite()]] - Write data to a file or stream | + | [[strlen()]] - Return the length of a < |
- | + | ||
- | [[fsockopen()]] - Open an internet socket connection with optional timeout | + | |
[[fopen()]] - Open a file for reading or writing | [[fopen()]] - Open a file for reading or writing | ||
+ | |||
+ | [[fseropen()]] - Open the serial port at the specified baud rate with optional parameters | ||
[[f485open()]] - Open the RS-485 port at the specified baud rate and parity | [[f485open()]] - Open the RS-485 port at the specified baud rate and parity | ||
- | [[fseropen()]] - Open the serial port at the specified baud rate with optional | + | [[fsockopen()]] - Open an internet socket connection |
+ | |||
+ | [[fread()]] - Read bytes from a file, stream or socket | ||
+ | |||
+ | [[fwrite()]] - Write data to a file, stream or socket | ||
+ | |||
+ | [[feof()]] - Test if no more data is available in a file, stream or socket | ||
+ | |||
+ | [[filesize()]] - Return the size of a file, or the number of unread bytes in a stream or socket | ||
+ | |||
+ | [[fseek()]] - Position the file pointer in an open file | ||
+ | |||
+ | [[ftell()]] - Return the current position of a file read/write pointer | ||
[[fclose()]] - Close a file, stream or socket | [[fclose()]] - Close a file, stream or socket | ||