note 41524 added to function.stream-wrapper-register

From: Date: Tue, 13 Apr 2004 14:53:43 +0000
Subject: note 41524 added to function.stream-wrapper-register
Groups: php.notes 
Request: Send a blank email to php-notes+get-68074@lists.php.net to get a copy of this message
using streams to use the ever useful fgetcsv() on a variable where explode() would not work (and would otherwise require regex(though that may be easier;))) $explode_this="yak, llama, 'big llama', 'wobmat, with a comma in it', bandycoot"; <?php class csvstream{ var $position; var $varname; function stream_open($path, $mode, $options, &$opened_path){ $url = parse_url($path); $this->varname = $url['host'] ; $this->position = 0; return true; } function stream_read($count){ $ret = substr($GLOBALS[$this->varname], $this->position, $count); $this->position += strlen($ret); return $ret; } function stream_eof(){ return $this->position >= strlen($GLOBALS[$this->varname]); } function stream_tell(){ return $this->position; } } stream_wrapper_register("csvstr", "csvstream") ; $str="yak, llama, 'big llama', 'wobmat, with a comma in it', bandycoot"; $fp = fopen("csvstr://str", "r+"); print_r(fgetcsv($fp,100,",","'")); ?> ---- Manual Page -- http://www.php.net/manual/en/function.stream-wrapper-register.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41524 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41524&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41524&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68074) next »