<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. PHP中的流是什么呢

    時間:2025-10-28 03:31:43 php語言

    PHP中的流是什么呢

      流(streams)是PHP4.3版本引入的一個特性,主要是為了統一文件、sockets以及其他類似資源的工作方法。PHP4.3距今已經有很長時間了,但是很多程序員似乎都不能正確使用PHP中的流,當然這也包括我。以前也在一些程序中遇到過流的使用,如php:/pic/p>

      概述

      流是由PHP提供的資源,可以供我們透明的使用,而且流是一個非常強大的工具。適當的在程序中使用流,可以將我們的程序帶到一個新的高度。

      PHP手冊中對流的描述如下:

      復制代碼 代碼如下:

      Streams were introduced with PHP 4.3.0 as a way of generalizing file, network, data compression, and other operations which share a common set of functions and uses. In its simplest definition, a stream is a resource object which exhibits streamable behavior. That is, it can be read from or written to in a linear fashion, and may be able to fseek() to an arbitrary locations within the stream.

      每一種流都實現了一個包裝器(wrapper),包裝器包含一些額外的代碼用來處理特殊的協議和編碼。PHP提供了一些內置的包裝器,我們也可以很輕松的創建和注冊自定義的包裝器。我們甚至可以使用上下文(contexts)和過濾器來改變和增強包裝器。

      流基礎知識

      PHP中流的形式如::/pic/p>

      默認的包裝器是file:/pic/path/to/somefile.txt')和readfile('file:/pic/path/to/somefile.txt'),使用這兩種方式讀取文件,可以得到相同的結果。

      正如前面所說,PHP提供了一些內置的包裝器、協議和過濾器。查看我們的機器上安裝了哪些包裝器,可以使用如下幾個函數:

      復制代碼 代碼如下:

      var_dump(stream_get_transports());

      var_dump(stream_get_wrappers());

      var_dump(stream_get_filters());

      ?>

      我本地的環境輸出內容如下:

      復制代碼 代碼如下:

      array (size=8)

      0 => string 'tcp' (length=3)

      1 => string 'udp' (length=3)

      2 => string 'unix' (length=4)

      3 => string 'udg' (length=3)

      4 => string 'ssl' (length=3)

      5 => string 'sslv3' (length=5)

      6 => string 'sslv2' (length=5)

      7 => string 'tls' (length=3)

      array (size=12)

      0 => string 'https' (length=5)

      1 => string 'ftps' (length=4)

      2 => string 'compress.zlib' (length=13)

      3 => string 'compress.bzip2' (length=14)

      4 => string 'php' (length=3)

      5 => string 'file' (length=4)

      6 => string 'glob' (length=4)

      7 => string 'data' (length=4)

      8 => string 'http' (length=4)

      9 => string 'ftp' (length=3)

      10 => string 'phar' (length=4)

      11 => string 'zip' (length=3)

      array (size=12)

      0 => string 'zlib.*' (length=6)

      1 => string 'bzip2.*' (length=7)

      2 => string 'convert.iconv.*' (length=15)

      3 => string 'string.rot13' (length=12)

      4 => string 'string.toupper' (length=14)

      5 => string 'string.tolower' (length=14)

      6 => string 'string.strip_tags' (length=17)

      7 => string 'convert.*' (length=9)

      8 => string 'consumed' (length=8)

      9 => string 'dechunk' (length=7)

      10 => string 'mcrypt.*' (length=8)

      11 => string 'mdecrypt.*' (length=10)

      另外,我們可以自定義或者使用第三方的流。

      php:/pic/strong>

      PHP有它自己的訪問輸入/輸出(I/O)流的包裝器。PHP有基本的php:/pic/pic/pic/O資源。還有一個php:/pic/p>

      因為php:/pic/p>

      復制代碼 代碼如下:

      1.php:/pic/pic/form-data

      2.僅當Content-Type為application/x-www-form-urlencoded且提交方法是POST方法時,$_POST數據與php:/pic/p>

      3.php:/pic/p>

      流上下文(Stream Contexts)

      這部分內容在編程中幾乎沒有遇到過,本人研究起來也比較吃力,大家感興趣的話可以自行百度。

    【PHP中的流是什么呢】相關文章:

    PHP中的流是什么01-09

    PHP中的Streams是什么07-30

    PHP中的trait是什么08-03

    PHP中MySql操作是什么02-09

    PHP7.1中重大更新是什么01-11

    php是什么11-15

    PHP中的Trait11-20

    PHP簡介是什么07-01

    PHP框架是什么11-13

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人