Skip to content

Instantly share code, notes, and snippets.

@jamesBan
Created September 24, 2020 03:46
Show Gist options
  • Save jamesBan/7284a341a054826421435c9a750f49b4 to your computer and use it in GitHub Desktop.
Save jamesBan/7284a341a054826421435c9a750f49b4 to your computer and use it in GitHub Desktop.
string to stream
<?php
$string = "I tried, honestly!";
$stream = fopen('data://text/plain,' . $string,'r');
echo stream_get_contents($stream);
$string = 'Some bad-ass string';
$stream = fopen('php://memory','r+');
fwrite($stream, $string);
rewind($stream);
echo stream_get_contents($stream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment