Example 1 — Remove a Write Filter Midway
Attach string.rot13 for the first write, remove it, then write again. Only the first part is encoded.
<?php
$fp = fopen("php://temp", "r+");
$filter = stream_filter_append($fp, "string.rot13", STREAM_FILTER_WRITE);
fwrite($fp, "This is ");
stream_filter_remove($filter);
fwrite($fp, "a test");
rewind($fp);
echo stream_get_contents($fp), PHP_EOL;
fclose($fp); How It Works
- php://temp opens an in-memory stream that behaves like a temporary file.
- stream_filter_append() adds string. rot13 on the write side and returns a filter resource.
- The first fwrite() is rot13-encoded; stream_filter_remove() detaches the filter afterward.
- The second fwrite() is stored as plain text, so the combined result is "Guvf vf a test".

