- stream_get_contents: documentation ( source)
- addslashes: documentation ( source)
- fclose: documentation ( source)
- fwrite: documentation ( source)
- rewind: documentation ( source)
- fopen: documentation ( source)
- ftruncate: documentation ( source)
<?php
$f = fopen('php://memory', 'w+');
fwrite($f, 'Hello');
ftruncate($f, 2); // in 7.3 changes file pointer to 2
fwrite($f, 'World');
rewind($f);
echo addslashes(stream_get_contents($f));
fclose($f);