移动网络电视错误代码91出现22002错误代码

日 ... ... 就读取缓存,返回结果,就是这个思路,看看这个源码:下面我打断这个代码逐行解释.
三、程序透析这个缓存类(类没什么好怕的.请继续看)名称是cache&...
日 ... PHP高级编程第一章:Php高级语法PhpDate()PHP引用文件Php文件处理PHP文件
上传PHPCookiesPHPSessionsPhpmail()函.
日 ... 批处理For语句从入门到精通(完整版)_.txt ..... [code7]的执行过程是:逐行
读取test.txt中的内容,以点号和逗号切分每一行 ..... 见:什么情况下该使用变量延迟
?-dos.net/forum/viewthread.php?tid=20733)说得&...
日 ... PHP高级编程,PHP高级编程免费下载:下载第章文件处理与数据存储如果想从PHP
页面上 ... PHP语言提供了处理非关系型数据库和文件系统的函数。
Visual Studio 2013开发MFC程序,逐行读取TXT文件的内容,重新写入Excel文件。
博文地址:http://blog.csdn.net/fish_55_66/article/details/。
日 ... php教程,php教程免费下载:PHP语法您无法在浏览器中通过查看源文档的方式来
查看PHP的源代码您只能看到PHP文件的输出即纯粹的HTML。
Visual Studio 2013开发MFC程序,逐行读取TXT文件的内容,重新写入Excel文件。
博文地址:http://blog.csdn.net/fish_55_66/article/details/。
Visual Studio 2013开发MFC程序,逐行读取TXT文件的内容,重新写入Excel文件。
... 压缩包里面包含了PHP Tools For Visual Studio 2013的安装文件和破解补本,&...
日 ... 从文件读取和写入数据(Input/Output)15212.文件访问类型15213.使用顺序文件
15214.读取储存于顺序文件里的数据15215.逐行读取文件15316.
日 ... 你的第一个程序 首先我将给出一段代码,接着再逐行进行解释。 .... 现在,当我们
已经得到 cpp-home.txt 文件时, 我们将要读取它,并且将内容打印&...java(22)
随机读取txt文件的某一行,每一行的概率都是一样的
public static String choose(File f) throws FileNotFoundException
String result =
Random rand = new Random();
int n = 0;
for(Scanner sc = new Scanner(f); sc.hasNext(); )
String line = sc.nextLine();
System.out.println(&n: &+n+& line: &+line);
if(rand.nextInt(n) == 0)
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:60991次
积分:1460
积分:1460
排名:千里之外
原创:75篇
转载:24篇
(1)(7)(11)(1)(9)(13)(1)(2)(4)(1)(1)(1)(1)(1)(5)(6)(8)(9)(3)(1)(4)(2)(3)(3)(1)(1)(3)(1)(1)(1)& 从文件指针中读取一行
PHP fgets 从文件指针中读取一行
fgets & 从文件指针中读取一行
string fgets
( int $handle
[, int $length
出错时返回 FALSE。
通常的缺陷:
习惯了 C 语言中 fgets() 语法的人应该注意到 EOF
是怎样被返回的。
文件指针必须是有效的,必须指向由
成功打开的文件(并还未由
以下是一个简单例子:
Example #1 逐行读取文件
&?php$handle&=&@fopen("/tmp/inputfile.txt",&"r");if&($handle)&{&&&&while&(!feof($handle))&{&&&&&&&&$buffer&=&fgets($handle,&4096);&&&&&&&&echo&$buffer;&&&&}&&&&fclose($handle);}?&
length 参数从 PHP 4.2.0
起成为可选项,如果忽略,则行的长度被假定为 1024。从 PHP 4.3 开始,忽略掉
length 将继续从流中读取数据直到行结束。如果文件中的大多数行都大于
8KB,则在脚本中指定最大行的长度在利用资源上更为有效。
从 PHP 4.3 开始本函数可以安全用于二进制文件。早期的版本则不行。
Note: 在读取在 Macintosh 电脑中或由其创建的文件时, 如果 PHP
不能正确的识别行结束符,启用运行时配置可选项 auto_detect_line_endings
也许可以解决此问题。
参见 ,,,,,,
PHP fgets note #1
There seems to be an interaction between sockets and the auto_detect_line_endings setting that can cause rather peculiar behavior. Apparently, if the first line read from a socket is split across two TCP packets, the detector will look at the first TCP packet and determine that the system uses MacOS (
) line endings, even though the LF is contained in the next packet. For example, this affected the PEAR Net_SMTP package, which would fail mysteriously for only some email servers.
PHP fgets note #2
To have fgets get data from a (for instance binary) string this might be of help:
$data = "the string data
to parse";
$fp = fopen('data:text/plain,'. $data,'rb');
while ( ($line = fgets($fp)) !== false) {
& echo "$line&br&";
PHP fgets note #3
Some people try to call feof before fgets, and then ignoring the return value of fgets. This method leads to processing value FALSE when reaching the end of file.
Bad example:
&&& $f = fopen ("fgetstest.php", "r");
&&& $ln= 0;
&&& while (! feof ($f)) {
&& & && $line= fgets ($f);
&& & && ++$ln;
&& & && printf ("%2d: ", $ln);
&& & && if ($line===FALSE) print ("FALSE
&& & && else print ($line);
&&& fclose ($f);
Good example:
&&& $f = fopen ("fgetstest.php", "r");
&&& $ln= 0;
&&& while ($line= fgets ($f)) {
&& & && ++$ln;
&& & && printf ("%2d: ", $ln);
&& & && if ($line===FALSE) print ("FALSE
&& & && else print ($line);
&&& fclose ($f);
PHP fgets note #4
One thing I discovered with fgets, at least with PHP 5.1.6, is that you may have to use an IF statement to avoid your code running rampant (and possibly hanging the server).& This can cause problems if you do not have root access on the server on which you are working.
This is the code I have implemented ($F1 is an array):
&& if($fh = fopen("filename","r")){
&& && while (!feof($fh)){
&& & & & $F1[] = fgets($fh,9999);
&& && fclose($fh);
I have noticed that without the IF statement, fgets seems to ignore when $fh is undefined (i.e., "filename" does not exist).& If that happens, it will keep attempting to read from a nonexistent filehandle until the process can be administratively killed or the server hangs, whichever comes first.
PHP fgets note #5
As I noted in a comment on stream_get_line() page, fgets is *not* necessarily slower than stream_get_line(). In my case, it's actually ~2.5 times slower. (25 seconds vs 10 seconds)
Also, stream_get_line() doesn't return the limiter. Since you pass both a maximum string length, you have no way of knowing whether or not the limiter was present in the original file, other than the 1 in 1024 chance that the line (with limiter) is exactly 1024 characters long, and appending the limiter (EG: "
") in the case where the line is less than 1024 chars.
This latter bit compromises data integrity, stream_get_line() should probably not be used for all but very special cases.
PHP fgets note #6
Here my solution for the " problem [in CSV files.& This function uses fgets(), not fgetcsv().]
define("CSV_Start",& & 0);
define("CSV_Quoted",&& 1);
define("CSV_Quoted2",& 2);
define("CSV_Unquoted", 3);
function readCSV($fh, $len, $delimiter = ',', $enclosure = '"') {
&&& $data = Array();
&&& $fildNr = 0;
&&& $state = CSV_Start;
&&& $data[0] = "";
&& & && $line = fgets($fh, $len);
&& & && for ($ix = 0; $ix & strlen($line); $ix++) {
&& & & & && if ($line[$ix] == $delimiter) {
&& & & & & & && if ($state != CSV_Quoted) {
&& & & & & & & & && $fildNr++;
&& & & & & & & & && $data[$fildNr] = "";
&& & & & & & & & && $state = CSV_Start;
&& & & & & & && } else {
&& & & & & & & & && $data[$fildNr] .= $line[$ix];
&& & & & & & && }
&& & & & && } elseif ($line[$ix] == $enclosure) {
&& & & & & & && if ($state == CSV_Start) {
&& & & & & & & & && $state = CSV_Quoted;
&& & & & & & && } elseif ($state == CSV_Quoted) {
&& & & & & & & & && $state = CSV_Quoted2;
&& & & & & & && } elseif ($state == CSV_Quoted2) {
&& & & & & & & & && $data[$fildNr] .= $line[$ix];
&& & & & & & & & && $state = CSV_Quoted;
&& & & & & & && } else {
&& & & & & & & & && $data[$fildNr] .= $line[$ix];
&& & & & & & && }
&& & & & && } else {
&& & & & & & && $data[$fildNr] .= $line[$ix];
&& & & & & & && if ($state == CSV_Quoted2) {
&& & & & & & & & && echo "error";
&& & & & & & && } elseif ($state == CSV_Start) {
&& & & & & & & & && $state = CSV_Unquoted;
&& & & & & & && }
&& & & & && }
&&& } while ($state == CSV_Quoted);
&&& return $data;&&
PHP fgets note #7
As fgets uses char(10) LF as separator instead of ch(13) CF is caused me problem in using the read value(e.g. "XYZ
"& in system() command(e.g. system("XYZ
option") was& interpreted as only system("XYZ") due to
would have to striped out first.
PHP fgets note #8
For large files, consider using stream_get_line rather than fgets - it can make a significant difference.
$ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdin","r"); while($line=stream_get_line($fp,65535,"
")) { 1; } fclose($fp);'
real& & 0m1.482s
user& & 0m1.616s
sys& & 0m0.152s
$ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdin","r"); while($line=fgets($fp,65535)) { 1; } fclose($fp);'
real& & 0m7.281s
user& & 0m7.392s
sys& & 0m0.136s
PHP fgets note #9
I ran into an issue that took me forever to finally figure out today, and I wanted to post my findings here in case anyone else ever runs into the same thing. I had tried to open a connection using fsockopen to my own server, send some data with fwrite, and then read the response with fgets. The data I sent over included the session ID, which was to be loaded by the page receiving it. Keep in mind that both the sender and receiver URLs were on my same server, and both tried to use the same session ID.
I found that I could do the fwrite part just fine, but that fgets would lock up indefinitely, ignoring any timeout I had set with fsockopen (but thankfully still obeying the max_execution_time limit).
The problem was that while the sending page was trying to do the fgets, it still had the session open. But the receiving page needed session data before it was willing to output anything, thereby creating a deadlock.
The solution I found was to call session_write_close() just prior to sending the request in the sender page, thereby granting access for the receiver to open up the session variables it needed.
PHP fgets note #10
Reply to Jerem's note. fgets terminating on chr(10) is correct.
For the sake of you youngsters who have never heard of such things, the protocol for the CRLF pair dates back to the days where the input/output with computers was on teletype machines. A sort of glorified typewriter.
chr(13) is a carriage return (CR), a command which physically moved the type head to the home position and chr(10) is a line feed (LF), which moved the paper up a line.
The standard order in which these were used was CRLF - chr(13)/chr(10) - and both were needed for a line break. Use a CR chr(13) on its own and you would overwrite the beginning of the same line. (Incidentally, this was how bold type was done - print the same thing in the same place twice!). Use LF chr(10) on its own and you would continue printing at the current position across the page but dropped down a line. (Because the paper would move up but the print head remain where it is).
Usage of this protocol has become somewhat sloppy and ill-defined these days for both printers and monitors. Some applications expect a line feed chr(10) on its own and simply assume a carriage return, others still use both but often without observing their distinctly separate functions. So much so that it may sometimes appear that they both do more or less the same thing, you only need one of them, and which to use is purely a matter of personal choice. Wrong on all counts!
fgets terminating on a LF chr(10) is correct as it ensures that the preceding CR chr(13) is included in the line if it is present - and doesn't matter if it isn't. If fgets ever terminated on CR chr(13) as jerem suggests more often than not there would be a LF at the beginning of the next line read.
The prefered use of chr(13) alone as a line break is risky. You might get away with it using your own applications and current printer, but if your file is for general release other people would see the entire output of your file printed on the same line if they use applications that interpret the CRLF pair more correctly. Not what you intended!
PHP fgets note #11
It's worth noting that this function only assumes chr(10) as a line break, but not chr(13). Personally, I prefer using chr(13) as a line break.
PHP fgets note #12
The file pointer that fgets() uses can also be created with the proc_open() function and used with the stdout pipe created from the executed process.
PHP fgets note #13
If you use the example from the command-description, i recommend to trim the $buffer for further use. The line feed ist still at the end of the line. I saw this when using PHP CLI.
Like this, checking a file-list for existing entries:
$handle = fopen ("/tmp/files.txt", "r");
while (!feof($handle)) {
&&& $buffer = fgets($handle, 4096);
&&& if (file_exists(rtrim($filename,"
&& & && echo $
&&& } else {
&& & && echo $buffer." has been removed."
fclose ($handle);
PHP fgets note #14
I'm using this function to modify the header of a large postscript document on copy...& Works extremely quickly so far...
function write($filename) {
&& & $fh = fopen($this-&sourceps,'r');
&& & $fw = fopen($filename,'w');
&& & while (!feof($fh)) {
&& & & $buffer = fgets($fh);
&& & & fwrite($fw,$buffer);
&& & & if (!$setupfound && ereg("^%%BeginSetup",$buffer)) {
&& & & & $setupfound++;
&& & & & if (array_key_exists("$filename",$this-&output)) {
&& & & & & foreach ($this-&output[$filename] as $function =& $value) {
&& & & & & & fwrite($fw,$value);
&& & & & & }
&& & & & }
&& & & & stream_copy_to_stream($fh,$fw);
&& & fclose($fw);
&& & fclose($fh);
PHP fgets note #15
fscanf($file, "%s
") isn't really a good substitution for fgets(), since it will stop parsing at the first whitespace and not at the end of line!
(See the fscanf page for details on this)
PHP fgets note #16
There's an error in the documentation:
The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
You should also add "popen" and "pclose" to the documentation. I'm a new PHP developer and went to verify that I could use "fgets" on commands that I used with "popen".
PHP fgets note #17
For sockets, If you dont want fgets, fgetc etc... to block if theres no data there. set socket_set_blocking(handle,false); and socket_set_blocking(handle,true); to set it back again.
PHP fgets note #18
fgets is SLOW for scanning through large files. If you don't have PHP 5, use fscanf($file, "%s
") instead.
PHP fgets note #19
An easy way to authenticate Windows Domain users from scripts running on a non-Windows or non-Domain box - pass the submitted username and password to an IMAP service on a Windows machine.
$server = 'imapserver';
$user = 'user';
$pass = 'pass';
if (authIMAP($user, $pass, $server)) {
&&& echo "yay";
&&& echo "nay";
function authIMAP($user, $pass, $server) {
&&& $connection = fsockopen($server, 143, $errno, $errstr, 30);
&&& if(!$connection) return false;
&&& $output = fgets($connection, 128); fputs($connection, "1 login $user $pass
&&& $output = fgets($connection, 128);
&&& fputs($connection, "2 logout
&&& fclose($connection);
&&& if (substr($output, 0, 4) == '1 OK') return true;
&&& return false;
PHP fgets note #20
Macintosh line endings mentioned in docs refer to Mac OS Classic. You don't need this setting for interoperability with unixish OS X.
PHP fgets note #21
I think that the quickest way of read a (long) file with the rows in& reverse order is
$myfile = 'myfile.txt';
$command = "tac $myfile & /tmp/myfilereversed.txt";
passthru($command);
$ic_max = 100;& $handle = fopen("/tmp/myfilereversed.txt", "r");
while (!feof($handle) && ++$ic&=$ic_max) {
&& $buffer = fgets($handle, 4096);
&& echo $buffer."&br&";
fclose($handle);
It echos the rows while it is reading the file so it is good for long files like logs.
PHP fgets note #22
I would have expected the same behaviour from these bits of code:-
while (!feof($fp)) {
&&& echo fgets($fp);
while ($line=fgets($fp)) {
&&& echo $line;
stream_set_timeout($fp, 180);
while ($line=fgets($fp)) {
&&& echo $line;
PHP fgets note #23
When working with VERY large files, php tends to fall over sideways and die.&
Here is a neat way to pull chunks out of a file very fast and won't stop in mid line, but rater at end of last known line.& It pulled a 30+ million line 900meg file through in ~ 24 seconds.
$buf just hold current chunk of data to work with.& If you try "$buf .=" (note 'dot' in from of '=') to append $buff, script will come to grinding crawl around 100megs of data, so work with current data then move on!
//File to be opened
$file = "huge.file";
//Open file (DON'T USE a+ pointer will be wrong!)
$fp = fopen($file, 'r');
//Read 16meg chunks
$part = 0;
while(!feof($fp)) {
&&& $rbuf = fread($fp, $read);
&&& for($i=$$i & 0 || $n == chr(10);$i--) {
&& & && $n=substr($rbuf, $i, 1);
&& & && if($n == chr(10))
&& & && //If we are at the end of the file, just grab the rest and stop loop
&& & && elseif(feof($fp)) {
&& & & & && $i = $
&& & & & && $buf = substr($rbuf, 0, $i+1);
&& & & & &&
&&& //This is the buffer we want to do stuff with, maybe thow to a function?
&&& $buf = substr($rbuf, 0, $i+1);
&&& //Point marker back to last
&&& $part = ftell($fp)-($read-($i+1));
&&& fseek($fp, $part);
fclose($fp);
PHP fgets note #24
It appears that fgets() will return FALSE on EOF (before feof has a chance to read it), so this code will throw an exception:
while (!feof($fh)) {
& $line = fgets($fh);
& if ($line === false) {
&&& throw new Exception("File read error");
PHP fgets note #25
Saku's example may also be used like this:
&@ $pointer = fopen("$DOCUMENT_ROOT/foo.txt", "r"); if ($pointer) {
&& & while (!feof($pointer)) {
&& & & & $preTEXT = fgets($pointer, 999);
&& & & & $ATEXT[$I] = $preTEXT;& $I++;
&& & fclose($pointer);
PHP fgets note #26
Sometimes the strings you want to read from a file are not separated by an end of line character.& the C style getline() function solves this.& Here is my version:
function getline( $fp, $delim )
&&& $result = "";
&&& while( !feof( $fp ) )
&& & && $tmp = fgetc( $fp );
&& & && if( $tmp == $delim )
&& & & & && return $result;
&& & && $result .= $tmp;
&&& return $result;
$fp = fopen("/path/to/file.ext", 'r');
while( !feof($fp) )
&&& $str = getline($fp, '|');
fclose($fp);
PHP fgets note #27
Note that - afaik - fgets reads a line until it reaches a line feed (\n). Carriage returns (\r) aren't processed as line endings.
However, nl2br insterts a &br /& tag before carriage returns as well.
This is useful (but not nice - I must admit) when you want to store a more lines in one.
function write_lines($text) {
& $file = fopen('data.txt', 'a');
& fwrite($file, str_replace("
", ' ', $text)."
& fclose($file);
function read_all() {
& $file = fopen('data.txt', 'r');
& while (!feof($file)) {
&&& $line = fgets($file);
&&& echo '&u&Section&/u&&p&nl2br'.($line).'&/p&';
& fclose($file);
PHP fgets note #28
If you need to simulate an un-buffered fgets so that stdin doesnt hang there waiting for some input (i.e. it reads only if there is data available) use this :
&&& function fgets_u($pStdn) {
&& & & & && $pArr = array($pStdn);
&& & && if (false === ($num_changed_streams = stream_select($pArr, $write = NULL, $except = NULL, 0))) {
&& & & & && print("$ 001 Socket Error : UNABLE TO WATCH STDIN.
&& & & & && return FALSE;
&& & && } elseif ($num_changed_streams & 0) {
&& & & & & & && return trim(fgets($pStdn, 1024));
&& & & & &&
PHP fgets note #29
If you need to read an entire file into a string, use file_get_contents().& fgets() is most useful when you need to process the lines of a file separately.
PHP fgets note #30
As a beginner I would have liked to see "how to read a file into a string for use later and not only how to directly echo the fgets() result. This is what I derived:
&@ $pointer = fopen("$DOCUMENT_ROOT/foo.txt", "r"); if ($pointer) {
&& && while (!feof($pointer)) {
&& & & & $preTEXT = fgets($pointer, 999);
&& & & & $TEXT = $TEXT . $preTEXT;
&& && fclose($pointer);
PHP fgets note #31
If you have troubles reading binary data with versions &= 4.3.2 then upgrade to 4.3.3
The binary safe implementation seems to have had bugs which were fixed in 4.3.3
PHP fgets note #32
For all those people struggling with Macintosh conversions, since PHP 4.3 there is a new runtime setting available:
auto_detect_line_endings boolean
When turned on, PHP will examine the data read by fgets() and file() to see if it is using Unix, MS-Dos or Macintosh line-ending conventions.
This enables PHP to interoperate with Macintosh systems, but defaults to Off, as there is a very small performance penalty when detecting the EOL conventions for the first line, and also because people using carriage-returns as item separators under Unix systems would experience non-backwards-compatible behaviour.
PHPFilesystem - 函数

我要回帖

更多关于 网络电视错误代码1001 的文章

 

随机推荐