Created
February 15, 2012 02:11
-
-
Save ichikaway/1832549 to your computer and use it in GitHub Desktop.
stream wrapper for variable input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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