Example 1 — Uppercase Writes With string.toupper
Append string.toupper on a memory stream and write lowercase text.
<?php
$fp = fopen("php://memory", "w+");
stream_filter_append($fp, "string.toupper", STREAM_FILTER_WRITE);
fwrite($fp, "hello filter");
rewind($fp);
echo stream_get_contents($fp), PHP_EOL;
fclose($fp); How It Works
- php://memory is opened for reading and writing.
- string. toupper is appended on the write chain.
- fwrite() sends lowercase text through the filter.
- After rewind, the stored text is HELLO FILTER.

