PHP.mk документација

stream_filter_append

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.stream-filter-append.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.stream-filter-append.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
stream_filter_append

Референца за `function.stream-filter-append.php` со подобрена типографија и навигација.

function.stream-filter-append.php

stream_filter_append

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

stream_filter_appendAttach a filter to a stream

= NULL

stream_filter_append(
         resource $stream,
         string $filter_name,
         int $mode = ?,
         mixed $params = ?
): resource

Додава filter_name Прикачи филтер на поток stream.

Параметри

stream

Поставете ја големината на делот од протокот.

filter_name

на списокот на филтри прикачени на

mode

Стандардно, stream_filter_append() Името на филтерот. read filter chain ќе го прикачи филтерот на rако датотеката беше отворена за читање (т.е. Режим на датотека: +, и/или write filter chain ). Филтерот исто така ќе биде прикачен на w, aако датотеката беше отворена за читање (т.е. Режим на датотека: +). STREAM_FILTER_READ, STREAM_FILTER_WRITEако датотеката беше отворена за читање (т.е. Режим на датотека: STREAM_FILTER_ALL ако датотеката беше отворена за пишување (т.е. Режим на датотека: mode може да се помине и на

params

параметар за да се надмине ова однесување. params на end Овој филтер ќе биде додаден со наведениот stream_filter_prepend().

Вратени вредности

од списокот и затоа ќе се повика последен за време на операциите на потокот. За да додадете филтер на почетокот на списокот, користете false Враќа ресурс при успех или stream_filter_remove().

false се враќа ако stream при неуспех. Ресурсот може да се користи за упатување на оваа инстанца на филтерот за време на повик до filter_name не е ресурс или ако

Примери

не може да се најде.

<?php
/* Open a test file for reading and writing */
$fp = fopen('test.txt', 'w+');

/* Apply the ROT13 filter to the
* write filter chain, but not the
* read filter chain */
stream_filter_append($fp, "string.rot13", STREAM_FILTER_WRITE);

/* Write a simple string to the file
* it will be ROT13 transformed on the
* way out */
fwrite($fp, "This is a test\n");

/* Back up to the beginning of the file */
rewind($fp);

/* Read the contents of the file back out.
* Had the filter been applied to the
* read filter chain as well, we would see
* the text ROT13ed back to its original state */
fpassthru($fp);

fclose($fp);

/* Expected Output
---------------

Guvf vf n grfg

*/
?>

Белешки

Забелешка: Пример #1 Контролирање каде се применуваат филтрите
stream_filter_register() Кога користите прилагодени (кориснички) филтри filter_name.

Забелешка: мора да се повика прво за да се регистрира посакуваниот кориснички филтер на stream_filter_prepend().

Забелешка: Кога се додава филтер за читање и запишување, се создаваат две инстанци на филтерот. stream_filter_append() мора да се повика двапати со STREAM_FILTER_READ and STREAM_FILTER_WRITE за да се добијат двата ресурси на филтерот.

Види Исто така

Белешки од корисници 2 забелешки

Дан Џ
пред 10 години
Note that stream filters applied to STDOUT are not called when outputting via echo or print.

This is easily demonstrated with the standard ROT13 filter:
<?php
stream_filter_append( STDOUT, "string.rot13" );

print "Hello PHP\n";
// Prints "Hello PHP"

fprintf( STDOUT, "Hello PHP\n" );
// Prints "Uryyb CUC"
?>

If you want to filter STDOUT, you may have better luck with an output buffering callback added via ob_start:
http://php.net/manual/en/function.ob-start.php

At the time of this writing, there is an open PHP feature request to support echo and print for stream filters:
https://bugs.php.net/bug.php?id=30583
net_navard на yahoo точка com
20 години пред
Hello firends

The difference betweem adding a stream filter first or last in the filte list in only the order they will be applied to streams.

For example, if you're reading data from a file, and a given filter is placed in first place with stream_filter_prepend()the data will be processed by that filter first.

This example reads out file data and the filter is applied at the beginning of the reading operation:

<?php
/* Open a test file for reading */
$fp = fopen("test.txt", "r");
/* Apply the ROT13 filter to the
 * read filter chain, but not the
 * write filter chain */
stream_filter_prepend($fp, "string.rot13",
STREAM_FILTER_READ);
// read file data
$contents=fread($fp,1024);
// file data is first filtered and stored in $contents
echo $contents;
fclose($fp);
?>

On the other hand, if stream_filter_append() is used, then the filter will be applied at the end of the data operation. The thing about this is only the order filters are applied to streams. Back to the example, it's not the same thing removing new lines from file data and then counting the number of characters, than performing the inverse process. In this case, the order that filters are applied to stream is important.

This example writes a test string to a file. The filter is applied at the end of the writing operation:

<?php
/* Open a test file for writing */
$fp = fopen("test.txt", "w+");
/* Apply the ROT13 filter to the
 * write filter chain, but not the
 * read filter chain */
stream_filter_append($fp, "string.rot13",
STREAM_FILTER_WRITE);
/* Write a simple string to the file
 * it will be ROT13 transformed at the end of the
stream operation
 * way out */
fwrite($fp, "This is a test\n"); // string data is
first written, then ROT13 tranformed and lastly
written to file
/* Back up to the beginning of the file */
rewind($fp);
$contents=fread($fp,512);
fclose($fp);
echo $contents;
?>

In the first case, data is transformed at the end of the writing operation, while in the second one, data is first filtered and then stored in $contents.

                          With Regards 
                              Hossein
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.