标签:
fwrite() 把 string 的内容写入文件指针 file 处。 如果指定了 length,当写入了 length 个字节或者写完了 string 以后,写入就会停止,视乎先碰到哪种情况。 fwrite() 返回写入的字符数,出现错误时则返回 false。
<?php $file = fopen("test.txt","w"); echo fwrite($file,"Hello World. Testing!"); fclose($file); ?>
如果文件指针到了 EOF 或者出错时则返回 TRUE, 否则返回一个错误(包括 socket 超时),其它情况则返回 FALSE。 file 参数是一个文件指针。这个文件指针必须有效,并且必须指向一个由 fopen() 或 fsockopen() 成功打开(但还没有被 fclose() 关闭)的文件。
提示:feof() 函数对遍历长度未知的数据很有用。
注意:如果服务器没有关闭由 fsockopen() 所打开的连接,feof() 会一直等待直到超时而返回 TRUE。默认的超时限制是 60 秒,可以使用 stream_set_timeout() 来改变这个值。
注意:如果传递的文件指针无效可能会陷入无限循环中,因为 EOF 不会返回 TRUE。
<?php $file = fopen("test.txt", "r"); //输出文本中所有的行,直到文件结束为止。 while(! feof($file)){ echo fgets($file). "<br />"; }W fclose($file); ?>
fputs(file,string,length)
<?php $file = fopen("test.txt","w"); echo fputs($file,"Hello World. Testing!"); fclose($file); ?>
<?php $file = fopen("test.txt","r"); while(! feof($file)) { echo fgets($file). "<br />"; } fclose($file); ?>
fgetss(file,length,tags) 可以用可选的第三个参数 tags 指定哪些标记不被去掉。若失败,则返回 false。
<?php $file = fopen("test.htm","r"); echo fgetss($file,1024,"<p>,<b>"); fclose($file); ?>
以下是获取whois 信息的代码
function whois_query($domain) { // fix the domain name: $domain = strtolower(trim($domain)); $domain = preg_replace(‘/^http:\/\//i‘, ‘‘, $domain); $domain = preg_replace(‘/^www\./i‘, ‘‘, $domain); $domain = explode(‘/‘, $domain); $domain = trim($domain[0]); // split the TLD from domain name $_domain = explode(‘.‘, $domain); $lst = count($_domain) - 1; $ext = $_domain[$lst]; // You find resources and lists // like these on wikipedia: // http://de.wikipedia.org/wiki/Whois $servers = array( "biz" => "whois.neulevel.biz", "com" => "whois.internic.net", "us" => "whois.nic.us", "coop" => "whois.nic.coop", "info" => "whois.nic.info", "name" => "whois.nic.name", "net" => "whois.internic.net", "gov" => "whois.nic.gov", "edu" => "whois.internic.net", "mil" => "rs.internic.net", "int" => "whois.iana.org", "ac" => "whois.nic.ac", "ae" => "whois.uaenic.ae", "at" => "whois.ripe.net", "au" => "whois.aunic.net", "be" => "whois.dns.be", "bg" => "whois.ripe.net", "br" => "whois.registro.br", "bz" => "whois.belizenic.bz", "ca" => "whois.cira.ca", "cc" => "whois.nic.cc", "ch" => "whois.nic.ch", "cl" => "whois.nic.cl", "cn" => "whois.cnnic.net.cn", "cz" => "whois.nic.cz", "de" => "whois.nic.de", "fr" => "whois.nic.fr", "hu" => "whois.nic.hu", "ie" => "whois.domainregistry.ie", "il" => "whois.isoc.org.il", "in" => "whois.ncst.ernet.in", "ir" => "whois.nic.ir", "mc" => "whois.ripe.net", "to" => "whois.tonic.to", "tv" => "whois.tv", "ru" => "whois.ripn.net", "org" => "whois.pir.org", "aero" => "whois.information.aero", "nl" => "whois.domain-registry.nl" ); if (!isset($servers[$ext])) { die(‘Error: No matching nic server found!‘); } $nic_server = $servers[$ext]; $output = ‘‘; // connect to whois server: if ($conn = fsockopen($nic_server, 43)) { fputs($conn, $domain . "\r\n"); while (!feof($conn)) { $output .= fgets($conn, 128); } fclose($conn); } else { die(‘Error: Could not connect to ‘ . $nic_server . ‘!‘); } return $output; } $domain = ‘www.qiangbi.net/a.html‘; $output = whois_query($domain); print_r($output);
标签:
原文地址:http://www.cnblogs.com/timelesszhuang/p/4827970.html