Skip to content

Instantly share code, notes, and snippets.

@ichikaway
Created February 15, 2012 02:11
Show Gist options
  • Save ichikaway/1832549 to your computer and use it in GitHub Desktop.
Save ichikaway/1832549 to your computer and use it in GitHub Desktop.
stream wrapper for variable input
<?php
/**
* stream wrapper for variable input
* usage:
* $val = 'Hello <?php echo "World"; ?> hehe.';
* stream_wrapper_register("var", "VariableStream");
* include("var://".urlencode($val));
**/
class VariableStream {
public $position;
public $data = null;
public function url_stat() {
return;
}
public function stream_stat() {
return;
}
public function stream_open($path, $mode, $options, &$opened_path) {
$url = parse_url($path);
$this->data = urldecode($url["host"]);
$this->position = 0;
return true;
}
public function stream_read($count) {
$ret = substr($this->data, $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
public function stream_tell() {
return $this->position;
}
public function stream_eof() {
return $this->position >= strlen($this->data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment