@ 2015-12-01T19:19:24Z <?php
class StringStreamWrapper {
const PROTOCOL = "stringstream";
private $stringstream;
private $position;
private $stringlength;
public function stream_open($path, $mode, $options, &$opened_path) {
$contextOptions = stream_context_get_options($this->context);
if (!isset($contextOptions[self::PROTOCOL]['string']))
return false;
$this->position = 0;
// this is our stream!
$this->stringstream = $contextOptions[self::PROTOCOL]['string'];
$this->stringlength = strlen($this->stringstream);
return true;
}
public function stream_read($len) {
$data = substr($this->stringstream, $this->position, $len);
$this->position += strlen($data);
return $data;
}
public function stream_write($data){
$l = strlen($data);
$this->stringstream = substr($this->stringstream, 0, $this->position) . $data . substr($this->stringstream, $this->position += $l);
$this->stringlength = strlen($this->stringstream);
return $l;
}
public function stream_seek($offset, $whence = SEEK_SET) {
if ($whence == SEEK_CUR) {
$this->position += $offset;
}
else if ($whence == SEEK_END) {
$this->position = $this->stringlength + $offset;
}
else {
$this->position = $offset;
}
return true;
}
public function stream_tell() {
return $this->position;
}
public function stream_eof() {
return ($this->position >= $this->stringlength);
}
public function stream_stat() {
return array(
7 => $this->stringlength,
'size' => $this->stringlength,
);
}
static public function Open($string) {
$context = stream_context_create(array(self::PROTOCOL => array('string' => &$string)));
return fopen(self::PROTOCOL . "://",'r', false, $context);
}
}
stream_wrapper_register(StringStreamWrapper::PROTOCOL, "StringStreamWrapper");
class replace_nullchar_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = str_replace("\0", "", $bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
stream_filter_register('replacenullchar', 'replace_nullchar_filter');
class StringStreamWrapperFixed {
public static function bug68532fixed() {
if (defined('BUG68532FIXED'))
return BUG68532FIXED;
return version_compare(PHP_VERSION, '5.6.5', '>=') ||
(version_compare(PHP_VERSION, '5.5.21', '>=') && version_compare(PHP_VERSION, '5.6.0', '<'));
}
public static function Open($string) {
if (self::bug68532fixed()) {
$stream = fopen('php://temp', 'r+');
} else {
$stream = tmpfile();
}
fwrite($stream, $string);
rewind($stream);
return $stream;
}
}
#######################################
$testString = 'test';
echo "base64_encode = " . base64_encode($testString).PHP_EOL;
#######################################
# put some data in the StringStreamWrapper
#$stringstream = StringStreamWrapper::Open($testString);
# emulate the output stream (in memory)
$output = fopen('php://memory','r+');
# attach write filter to output
$filter = stream_filter_append($output, 'convert.base64-encode');
flush($output);
# write to output
#$written = stream_copy_to_stream($stringstream, $output);
fwrite($output, $testString);
# rewind
rewind($output);
# remove filter
stream_filter_remove($filter);
rewind($output);
echo "from outputstream = " . stream_get_contents($output).PHP_EOL;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks Deprecated: Return type of replace_nullchar_filter::filter($in, $out, &$consumed, $closing) should either be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/blrJl on line 74
base64_encode = dGVzdA==
Fatal error: Uncaught ArgumentCountError: flush() expects exactly 0 arguments, 1 given in /in/blrJl:122
Stack trace:
#0 /in/blrJl(122): flush(Resource id #6)
#1 {main}
thrown in /in/blrJl on line 122
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
59.45 ms | 401 KiB | 8 Q