本文整理汇总了PHP中fgets函数的典型用法代码示例。如果您正苦于以下问题:PHP fgets函数的具体用法?PHP fgets怎么用?PHP fgets使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fgets函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendData
protected static function sendData($host, $POST, $HEAD, $filepath, $mediafile, $TAIL)
{
$sock = fsockopen("ssl://" . $host, 443);
fwrite($sock, $POST);
fwrite($sock, $HEAD);
//write file data
$buf = 1024;
$totalread = 0;
$fp = fopen($filepath, "r");
while ($totalread < $mediafile['filesize']) {
$buff = fread($fp, $buf);
fwrite($sock, $buff, $buf);
$totalread += $buf;
}
//echo $TAIL;
fwrite($sock, $TAIL);
sleep(1);
$data = fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
fclose($sock);
list($header, $body) = preg_split("/\\R\\R/", $data, 2);
$json = json_decode($body);
if (!is_null($json)) {
return $json;
}
return false;
}
示例2: _recaptcha_http_post
/**
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
function _recaptcha_http_post($host, $path, $data, $port = 80)
{
$req = _recaptcha_qsencode($data);
$proxy_host = "proxy.iiit.ac.in";
$proxy_port = "8080";
$http_request = "POST http://{$host}{$path} HTTP/1.0\r\n";
$http_request .= "Host: {$host}\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
$http_request .= "\r\n";
$http_request .= $req;
$response = '';
if (false == ($fs = @fsockopen($proxy_host, $proxy_port, $errno, $errstr, 10))) {
die('Could not open socket aah');
}
fwrite($fs, $http_request);
while (!feof($fs)) {
$response .= fgets($fs, 1160);
}
// One TCP-IP packet
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
示例3: verifCode
function verifCode($decryptedTabIdMdp)
{
if (file_exists("C:\\wamp64\\www\\Web\\" . $decryptedTabIdMdp->identifiant) == true) {
//Si oui on ouvre le dossier et on recupere le mot de passe.
$handle = fopen("C:\\wamp64\\www\\Web\\" . $decryptedTabIdMdp->identifiant . "\\Confg.txt", "r+");
fgets($handle);
$Code = fgets($handle);
$Code = explode(":", $Code);
$Code = $Code[1];
fclose($handle);
$Code = dechiffrementdata($Code, $decryptedTabIdMdp->IV);
//On verifie le mot de passe
if ($Code == $decryptedTabIdMdp->code) {
// Si la comparraison est ok on renvoie vrai
$ok = "vrai\\\\" . $Code;
} else {
// Si la comparraison n'est pas correcte on renvoie faux
$Anwser = 'null';
$ok = "faux\\\\" . $Anwser;
}
return $ok;
} else {
$Anwser = 'null';
$ok = "faux\\\\" . $Anwser;
}
}
示例4: __construct
/**
* Constructor.
*
* @param Horde_Vcs_Base $rep A repository object.
* @param string $dn Path to the directory.
* @param array $opts Any additional options:
*
* @throws Horde_Vcs_Exception
*/
public function __construct(Horde_Vcs_Base $rep, $dn, $opts = array())
{
parent::__construct($rep, $dn, $opts);
$cmd = $rep->getCommand() . ' ls ' . escapeshellarg($rep->sourceroot . $this->_dirName);
$dir = proc_open($cmd, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
if (!$dir) {
throw new Horde_Vcs_Exception('Failed to execute svn ls: ' . $cmd);
}
if ($error = stream_get_contents($pipes[2])) {
proc_close($dir);
throw new Horde_Vcs_Exception($error);
}
/* Create two arrays - one of all the files, and the other of all the
* dirs. */
$errors = array();
while (!feof($pipes[1])) {
$line = chop(fgets($pipes[1], 1024));
if (!strlen($line)) {
continue;
}
if (substr($line, 0, 4) == 'svn:') {
$errors[] = $line;
} elseif (substr($line, -1) == '/') {
$this->_dirs[] = substr($line, 0, -1);
} else {
$this->_files[] = $rep->getFile($this->_dirName . '/' . $line);
}
}
proc_close($dir);
}
示例5: test_instam
function test_instam($key)
{
// returns array, or FALSE
// snap(basename(__FILE__) . __LINE__, $key_val);
// http://www.instamapper.com/api?action=getPositions&key=4899336036773934943
$url = "http://www.instamapper.com/api?action=getPositions&key={$key}";
$data = "";
if (function_exists("curl_init")) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
} else {
// not CURL
if ($fp = @fopen($url, "r")) {
while (!feof($fp) && strlen($data) < 9000) {
$data .= fgets($fp, 128);
}
fclose($fp);
} else {
// print "-error 1"; // @fopen fails
return FALSE;
}
}
/*
InstaMapper API v1.00
1263013328977,bold,1236239763,34.07413,-118.34940,25.0,0.0,335
1088203381874,CABOLD,1236255869,34.07701,-118.35262,27.0,0.4,72
*/
// dump($data);
$ary_data = explode("\n", $data);
return $ary_data;
}
示例6: send_mail
public function send_mail()
{
$talk = array();
if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) {
fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n");
$talk["hello"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "auth login\r\n");
$talk["res"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpUser . "\r\n");
$talk["user"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpPass . "\r\n");
$talk["pass"] = fgets($SMTPIN, 256);
fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n");
$talk["From"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n");
$talk["To"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"] = fgets($SMTPIN, 1024);
//Construct Headers
$headers = "MIME-Version: 1.0" . $this->newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $this->newLine;
$headers .= "From: <" . $this->from . ">" . $this->newLine;
$headers .= "To: <" . $this->to . ">" . $this->newLine;
$headers .= "Bcc: {$this->newLine}";
$headers .= "Subject: " . $this->subject . $this->newLine;
fputs($SMTPIN, $headers . "\r\n\r\n" . $this->body . "\r\n.\r\n");
$talk["send"] = fgets($SMTPIN, 256);
//CLOSE CONNECTION AND EXIT ...
fputs($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
}
return $talk;
}
示例7: convert_file
private function convert_file($source, $dest)
{
// Узнаем какая кодировка у файла
$teststring = file_get_contents($source, null, null, null, 1000000);
// Кодировка - UTF8
if (preg_match('//u', $teststring)) {
// Просто копируем файл
return copy($source, $dest);
} else {
// Конвертируем в UFT8
if (!($src = fopen($source, "r"))) {
return false;
}
if (!($dst = fopen($dest, "w"))) {
return false;
}
while (($line = fgets($src, 4096)) !== false) {
$line = $this->win_to_utf($line);
fwrite($dst, $line);
}
fclose($src);
fclose($dst);
return true;
}
}
示例8: sock_post
/**
* url 为服务的url地址
* query 为请求串
*/
private function sock_post($url, $query)
{
$data = "";
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 30);
if (!$fp) {
return $data;
}
$head = "POST " . $info['path'] . " HTTP/1.0\r\n";
$head .= "Host: " . $info['host'] . "\r\n";
$head .= "Referer: http://" . $info['host'] . $info['path'] . "\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: " . strlen(trim($query)) . "\r\n";
$head .= "\r\n";
$head .= trim($query);
$write = fputs($fp, $head);
$header = "";
while ($str = trim(fgets($fp, 4096))) {
$header .= $str;
}
while (!feof($fp)) {
$data .= fgets($fp, 4096);
}
return $data;
}
示例9: testLifetime
public function testLifetime()
{
$cache = $this->_getCacheDriver();
// Test save
$cache->save('test_key', 'testing this out', 10);
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key'));
// Test fetch
$this->assertEquals('testing this out', $cache->fetch('test_key'));
// access private methods
$getFilename = new \ReflectionMethod($cache, 'getFilename');
$getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
$getFilename->setAccessible(true);
$getNamespacedId->setAccessible(true);
$id = $getNamespacedId->invoke($cache, 'test_key');
$filename = $getFilename->invoke($cache, $id);
$data = '';
$lifetime = 0;
$resource = fopen($filename, "r");
if (false !== ($line = fgets($resource))) {
$lifetime = (int) $line;
}
while (false !== ($line = fgets($resource))) {
$data .= $line;
}
$this->assertNotEquals(0, $lifetime, 'previous lifetime could not be loaded');
// update lifetime
$lifetime = $lifetime - 20;
file_put_contents($filename, $lifetime . PHP_EOL . $data);
// test expired data
$this->assertFalse($cache->contains('test_key'));
$this->assertFalse($cache->fetch('test_key'));
}
示例10: SendMail
function SendMail()
{
if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) {
fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n");
$talk["hello"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "auth login\r\n");
$talk["res"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpUser . "\r\n");
$talk["user"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpPass . "\r\n");
$talk["pass"] = fgets($SMTPIN, 256);
fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n");
$talk["From"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n");
$talk["To"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "To: <" . $this->to . ">\r\nFrom: <" . $this->from . ">\r\nSubject:" . $this->subject . "\r\n\r\n\r\n" . $this->body . "\r\n.\r\n");
$talk["send"] = fgets($SMTPIN, 256);
//CLOSE CONNECTION AND EXIT ...
fputs($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
示例11: doPurge
/**
* Purge URL coming from stdin
*/
private function doPurge()
{
$stdin = $this->getStdin();
$urls = array();
while (!feof($stdin)) {
$page = trim(fgets($stdin));
if (preg_match('%^https?://%', $page)) {
$urls[] = $page;
} elseif ($page !== '') {
$title = Title::newFromText($page);
if ($title) {
$url = $title->getInternalURL();
$this->output("{$url}\n");
$urls[] = $url;
if ($this->getOption('purge')) {
$title->invalidateCache();
}
} else {
$this->output("(Invalid title '{$page}')\n");
}
}
}
$this->output("Purging " . count($urls) . " urls\n");
$this->sendPurgeRequest($urls);
}
示例12: jyxo_bot
function jyxo_bot($q = "", $d = "mm", $ereg = ".", $notereg = "", $cnt = 10000000000000, $page = 1, $pmax = 2, $o = "nocls")
{
$i = 0;
$results = "";
$results[$i] = "";
//$q = str_replace(" ", "+", $q);
$q = urlencode($q);
for (; $page <= $pmax; $page++) {
$request = "http://jyxo.cz/s?q={$q}&d={$d}&o={$o}&cnt={$cnt}&page={$page}";
$fp = fopen($request, "r") or die(" !!! Cannot connect !!!");
while (!feof($fp)) {
$line = fgets($fp);
if (eregi("<div class='r'>", $line) && ereg(" class=ri", $line)) {
$line = explode("<!--m--><div class='r'><A HREF=\"", $line);
$line = $line[1];
$line = explode("\" class=ri", $line);
$line = trim($line[0]);
$line = urldecode($line);
if (@eregi($ereg, $line) && !@eregi($notereg, $line) && !in_array($line, $results)) {
echo "{$line}\n";
//Output
//echo("$i:$line\n"); //Indexed Output
//echo("<a href=\"$line\">$line</a><br />\n"); //XHTML Output
$results[$i] = $line;
$i++;
}
}
}
fclose($fp);
}
echo "\nTotal: {$i}\n";
//Sumary Output
return $results;
}
示例13: _loadIni
/**
* _loadIni
*
* @param void
*
* @return void
**/
protected function _loadIni()
{
if(file_exists($this->_mFilePath)){
$key = null;
$file = fopen($this->_mFilePath, 'r');
for($lineNum=1; $line=fgets($file);$lineNum++){
if(substr($line,1,1)==';'||substr($line,1,1)=='#'||substr($line,1,2)=='//'){
continue;
}
elseif(preg_match('/\[(.*)\]/', $line, $str)){
if($this->_mSectionFlag===true){
$key = $str[1];
$this->_mConfig[$key] = array();
}
}
elseif(preg_match('/(.*)=(.*)/', $line, $str)){
if(preg_match('/^\"(.*)\"$/', $str[2], $body)||preg_match('/^\'(.*)\'$/', $str[2], $body)){
$str[2] = $body[1];
}
if($this->_mSectionFlag===true){
$this->_mConfig[$key][$str[1]] = $str[2];
}
else{
$this->_mConfig[$str[1]] = $str[2];
}
}
}
}
}
示例14: cli_read
function cli_read()
{
$handle = fopen("php://stdin", "r");
$line = trim(fgets($handle));
fclose($handle);
return $line;
}
示例15: getAllOptions
/**
* Retrieve all options array
*
* @return array
*/
public function getAllOptions()
{
$taxonomyPath = Mage::getBaseDir() . self::TAXONOMY_FILE_PATH;
$lang = Mage::getStoreConfig('general/locale/code', Mage::app()->getRequest()->getParam('store', 0));
$taxonomyFile = $taxonomyPath . "taxonomy-with-ids." . $lang . ".txt";
if (!file_exists($taxonomyFile)) {
$taxonomyFile = $taxonomyPath . "taxonomy-with-ids.en_US.txt";
}
if (is_null($this->_options)) {
$this->_options = array();
$this->_options[0] = array('value' => 0, 'label' => "0 Other");
if (($fh = fopen($taxonomyFile, "r")) !== false) {
$line = 0;
while (($category = fgets($fh)) !== false) {
$line++;
if ($line === 1) {
continue;
}
// skip first line
$option = explode(' - ', $category);
$this->_options[] = array('value' => $option[0], 'label' => $category);
}
}
}
return $this->_options;
}