当前位置: 首页>>代码示例>>PHP>>正文


PHP rewind函数代码示例

本文整理汇总了PHP中rewind函数的典型用法代码示例。如果您正苦于以下问题:PHP rewind函数的具体用法?PHP rewind怎么用?PHP rewind使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rewind函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Extract

 public function Extract($zn, $to, $index = array(-1))
 {
     $ok = 0;
     $zip = @fopen($zn, 'rb');
     if (!$zip) {
         return -1;
     }
     $cdir = $this->ReadCentralDir($zip, $zn);
     $pos_entry = $cdir['offset'];
     if (!is_array($index)) {
         $index = array($index);
     }
     for ($i = 0; $index[$i]; $i++) {
         if (intval($index[$i]) != $index[$i] || $index[$i] > $cdir['entries']) {
             return -1;
         }
     }
     $re = 0;
     for ($i = 0; $i < $cdir['entries']; $i++) {
         @fseek($zip, $pos_entry);
         $header = $this->ReadCentralFileHeaders($zip);
         $header['index'] = $i;
         $pos_entry = ftell($zip);
         @rewind($zip);
         fseek($zip, $header['offset']);
         if (in_array("-1", $index) || in_array($i, $index)) {
             $stat[$header['filename']] = $this->ExtractFile($header, $to, $zip);
         }
         $re = $stat[$header['filename']];
     }
     fclose($zip);
     return $re;
 }
开发者ID:BGCX261,项目名称:zlskytakeorder-svn-to-git,代码行数:33,代码来源:Unzip.php

示例2: dump

 public function dump(\Twig_Environment $env, $context)
 {
     if (!$env->isDebug()) {
         return;
     }
     if (2 === func_num_args()) {
         $vars = array();
         foreach ($context as $key => $value) {
             if (!$value instanceof \Twig_Template) {
                 $vars[$key] = $value;
             }
         }
         $vars = array($vars);
     } else {
         $vars = func_get_args();
         unset($vars[0], $vars[1]);
     }
     $dump = fopen('php://memory', 'r+b');
     $dumper = new HtmlDumper($dump);
     foreach ($vars as $value) {
         $dumper->dump($this->cloner->cloneVar($value));
     }
     rewind($dump);
     return stream_get_contents($dump);
 }
开发者ID:hannesvdvreken,项目名称:TwigBridge,代码行数:25,代码来源:Dump.php

示例3: updateIndex

function updateIndex($lang, $file)
{
    $fileData = readFileData($file);
    $filename = $file->getPathName();
    list($filename) = explode('.', $filename);
    $path = $filename . '.html';
    $id = str_replace($lang . '/', '', $filename);
    $id = str_replace('/', '-', $id);
    $id = trim($id, '-');
    $url = implode('/', array(ES_URL, ES_INDEX, $lang, $id));
    $data = array('contents' => $fileData['contents'], 'title' => $fileData['title'], 'url' => $path);
    $data = json_encode($data);
    $size = strlen($data);
    $fh = fopen('php://memory', 'rw');
    fwrite($fh, $data);
    rewind($fh);
    echo "Sending request:\n\tfile: {$file}\n\turl: {$url}\n";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_setopt($ch, CURLOPT_INFILE, $fh);
    curl_setopt($ch, CURLOPT_INFILESIZE, $size);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $metadata = curl_getinfo($ch);
    if ($metadata['http_code'] > 400) {
        echo "[ERROR] Failed to complete request.\n";
        var_dump($response);
        exit(2);
    }
    curl_close($ch);
    fclose($fh);
    echo "Sent {$file}\n";
}
开发者ID:ramonakira,项目名称:docs,代码行数:33,代码来源:populate_search_index.php

示例4: getMockFunctions

 private function getMockFunctions()
 {
     $functions = $this->getMock('FtpLib\\Functions', array('connect', 'ssl_connect', 'login', 'pasv', 'fput', 'delete', 'mkdir', 'chdir', 'fget', 'rmdir', 'nlist', 'size', 'close'));
     $functions->expects($this->any())->method('connect')->will($this->returnValue(true));
     $functions->expects($this->any())->method('ssl_connect')->will($this->returnValue(true));
     $functions->expects($this->any())->method('login')->will($this->returnValue(true));
     $functions->expects($this->any())->method('pasv')->will($this->returnValue(true));
     $functions->expects($this->any())->method('fput')->will($this->returnValue(true));
     $functions->expects($this->any())->method('delete')->will($this->returnValue(true));
     $functions->expects($this->any())->method('mkdir')->will($this->returnValue(true));
     $functions->expects($this->any())->method('chdir')->will($this->returnValue(true));
     $functions->expects($this->any())->method('chdir')->will($this->returnValue(true));
     $functions->expects($this->any())->method('rmdir')->will($this->returnValue(true));
     $functions->expects($this->any())->method('close')->will($this->returnValue(true));
     $functions->expects($this->any())->method('size')->will($this->returnValue(1));
     $functions->expects($this->any())->method('nlist')->will($this->returnCallback(function () {
         return array('filename1', 'filename2');
     }));
     $functions->expects($this->any())->method('fget')->will($this->returnCallback(function ($ftp_stream, $handle, $remote_file, $mode) {
         $tempHandle = fopen('php://temp', 'w+');
         fwrite($tempHandle, 'foo', strlen('foo'));
         rewind($tempHandle);
         $handle = $tempHandle;
         // AFAIK this doesn't work. PHP clones the parameters and cannot use references
         return true;
     }));
     return $functions;
 }
开发者ID:gonzalo123,项目名称:ftplib,代码行数:28,代码来源:FtpTest.php

示例5: resourceFactory

 /**
  * This method creates a new resource, and it seeds
  * the resource with lorem ipsum text. The returned
  * resource is readable, writable, and seekable.
  *
  * @param string $mode
  *
  * @return resource
  */
 public function resourceFactory($mode = 'r+')
 {
     $stream = fopen('php://temp', $mode);
     fwrite($stream, $this->text);
     rewind($stream);
     return $stream;
 }
开发者ID:hidayat365,项目名称:phpindonesia.or.id-membership2,代码行数:16,代码来源:BodyTest.php

示例6: extract_file

 function extract_file($zn, $to, $index = array(-1))
 {
     $ok = 0;
     $zip = @fopen($zn, 'rb');
     if (!$zip) {
         return -1;
     }
     $cdir = $this->rc_dir($zip, $zn);
     $pos_entry = $cdir['offset'];
     if (!is_array($index)) {
         $index = array($index);
     }
     for ($i = 0; isset($index[$i]); $i++) {
         if (intval($index[$i]) != $index[$i] || $index[$i] > $cdir['entries']) {
             return -1;
         }
     }
     for ($i = 0; $i < $cdir['entries']; $i++) {
         @fseek($zip, $pos_entry);
         $header = $this->rcf_header($zip);
         $header['index'] = $i;
         $pos_entry = ftell($zip);
         @rewind($zip);
         fseek($zip, $header['offset']);
         if (in_array("-1", $index) || in_array($i, $index)) {
             $stat[$header['filename']] = $this->uncompress($header, $to, $zip);
         }
     }
     fclose($zip);
     return $stat;
 }
开发者ID:Eidn,项目名称:shanghai,代码行数:31,代码来源:unzip.class.php

示例7: createTmpFile

 public static function createTmpFile($data)
 {
     $tmp_file = tmpfile();
     fwrite($tmp_file, $data);
     rewind($tmp_file);
     return $tmp_file;
 }
开发者ID:edwardstock,项目名称:php-curl-class,代码行数:7,代码来源:helper.inc.php

示例8: generate

 /**
  * Generates a CSV string from given array data
  *
  * @param array $data
  *
  * @throws \RuntimeException
  *
  * @return string
  */
 public function generate(array $data)
 {
     $fileHandle = fopen('php://temp', 'w');
     if (!$fileHandle) {
         throw new \RuntimeException("Cannot open temp file handle (php://temp)");
     }
     if (!is_array($data[0])) {
         $data = [$data];
     }
     $tmpPlaceholder = 'MJASCHEN_COLLMEX_WORKAROUND_PHP_BUG_43225_' . time();
     foreach ($data as $line) {
         // workaround for PHP bug 43225: temporarily insert a placeholder
         // between a backslash directly followed by a double-quote (for
         // string field values only)
         array_walk($line, function (&$item) use($tmpPlaceholder) {
             if (!is_string($item)) {
                 return;
             }
             $item = preg_replace('/(\\\\+)"/m', '$1' . $tmpPlaceholder . '"', $item);
         });
         fputcsv($fileHandle, $line, $this->delimiter, $this->enclosure);
     }
     rewind($fileHandle);
     $csv = stream_get_contents($fileHandle);
     fclose($fileHandle);
     // remove the temporary placeholder from the final CSV string
     $csv = str_replace($tmpPlaceholder, '', $csv);
     return $csv;
 }
开发者ID:mjaschen,项目名称:collmex,代码行数:38,代码来源:SimpleGenerator.php

示例9: restCall

 /**
  * A function to encapsulate rest based calls using the curl library.
  * 
  * @params $url      - OK to have ?foo=bar
  * @params $method   - GET/PUT/POST/DELETE
  * @params $payload  - data to send in if PUT/POST
  * @return array($response_code=>$data) - the function does NOT format response data.
  */
 public function restCall($endpoint, $method = 'GET', $payload = null, $headers = null)
 {
     if (empty($endpoint)) {
         return array(ResponseCodes::MISSING_PARAM => 'Missing server endpoint. This is the URL you intended to call and it was empty.');
     }
     $verifySSL = get_cfg_var('environment') == 'production' ? true : false;
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $endpoint);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $verifySSL);
     /*
      * Set the header to json since we will pass json out for all calls.
      */
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
     /*
      * Set any headers we were passed. We support a string or an array of strings.
      */
     if (!empty($headers)) {
         if (is_array($headers)) {
             curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
         } else {
             curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers));
         }
     }
     /*
      * Default method is GET
      */
     $method = empty($method) ? 'GET' : strtoupper($method);
     /*
      * Based on the method passed in, we need to set our data
      */
     if ($method == 'POST') {
         curl_setopt($curl, CURLOPT_POST, TRUE);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
     }
     if ($method == 'PUT') {
         $fh = fopen('php://memory', 'w+');
         fwrite($fh, $payload);
         rewind($fh);
         curl_setopt($curl, CURLOPT_INFILE, $fh);
         curl_setopt($curl, CURLOPT_INFILESIZE, strlen($payload));
         curl_setopt($curl, CURLOPT_PUT, TRUE);
     }
     if ($method == 'DELETE') {
         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
         if (!empty($payload)) {
             curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
         }
     }
     /*
      * Execute the request
      */
     $data = trim(curl_exec($curl));
     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     @fclose($fh);
     if (preg_match('/^({|\\[)/', $data) && preg_match('/(}|\\])$/m', $data)) {
         $data = json_encode($data, true);
     }
     return array($code => $data);
 }
开发者ID:armandocolpa,项目名称:rust-framework,代码行数:68,代码来源:CurlRequest.php

示例10: dom

 public static function dom($stream)
 {
     rewind($stream);
     $actual = stream_get_contents($stream);
     $html = DOMDocument::loadHTML($actual);
     return simplexml_import_dom($html);
 }
开发者ID:Clansuite,项目名称:Clansuite,代码行数:7,代码来源:coverage_calculator_test.php

示例11: rewind

	function rewind()
	{
		if (!$this->fp) return;
		rewind($this->fp);
		$this->rowno = 0;
		$this->next();
	}
开发者ID:nasneg,项目名称:Gen-for-CodeIgniter,代码行数:7,代码来源:Gen_file.php

示例12: testDoWrite

 public function testDoWrite()
 {
     $output = new StreamOutput($this->stream);
     $output->writeln('foo');
     rewind($output->getStream());
     $this->assertEquals('foo' . PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:7,代码来源:StreamOutputTest.php

示例13: reset

 /**
  * Resets the input stream.
  */
 public function reset()
 {
     if (!is_resource($this->_stream)) {
         throw new Opl_Stream_Exception('Input stream is not opened.');
     }
     rewind($this->_stream);
 }
开发者ID:OPL,项目名称:Open-Power-Libs,代码行数:10,代码来源:Input.php

示例14: logMaxIdForThisTime

 /**
  * 记录本次生成后的最大id,下次从这个id开始生成
  * @param $id
  * @return bool
  */
 public function logMaxIdForThisTime($id)
 {
     rewind($this->logHandler);
     $byte = fwrite($this->logHandler, $id);
     fflush($this->logHandler);
     return $byte > 0;
 }
开发者ID:silentred,项目名称:learning-path,代码行数:12,代码来源:SitemapController.php

示例15: RawAction

 public function RawAction()
 {
     $dataUriRegex = "/data:image\\/([\\w]*);([\\w]*),/i";
     //running a regex against a data uri might be slow.
     //Streams R fun.
     //  To avoid lots of processing before needed, copy just the first bit of the incoming data stream to a variable for checking.  rewind the stream after.  Part of the data will be MD5'd for storage.
     // note for
     $body = $this->detectRequestBody();
     $tempStream = fopen('php://temp', 'r+');
     stream_copy_to_stream($body, $tempStream, 500);
     rewind($tempStream);
     $uriHead = stream_get_contents($tempStream);
     $netid = isset($_SERVER['NETID']) ? $_SERVER['NETID'] : "notSet";
     $filename = $netid;
     $matches = array();
     // preg_match_all returns number of matches.
     if (0 < preg_match_all($dataUriRegex, $uriHead, $matches)) {
         $extension = $matches[1][0];
         $encoding = $matches[2][0];
         $start = 1 + strpos($uriHead, ",");
         $imageData = substr($uriHead, $start);
         // THERES NO ARRAY TO STRING CAST HERE PHP STFU
         $filename = (string) ("./cache/" . $filename . "-" . md5($imageData) . "." . $extension);
         $fileHandle = fopen($filename, "c");
         stream_filter_append($fileHandle, 'convert.base64-decode', STREAM_FILTER_WRITE);
         stream_copy_to_stream($body, $fileHandle, -1, $start);
     }
 }
开发者ID:CU-WebTech,项目名称:mimeograph,代码行数:28,代码来源:ImageController.php


注:本文中的rewind函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。