|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-14 11:39 UTC] jketterl at chipxonio dot de
Description: ------------ exact php version: PHP 5.2.11-0.dotdeb.1 with Suhosin-Patch 0.9.7 (cli) (built: Sep 20 2009 09:41:43) this bug is also be filter-/stream-related. i just believe it might be easier to fix on the filesystem side, that's why i chose that category. when using a php stream filter to convert input from utf-16 into iso8859 (or most probably from any 2byte-encoded charset into any single-byte-encode charset) the ftell() and fseek() functions start to behave inconsistently. more precisely: fseek() jumps to exact offsets ignoring the 2byte-encoding, whereas ftell() seems to return the number of bytes read *after* the filter has been applied. thus it is not possible to fseek() back to a certain offset that has been stored with ftell() before. the content of the testfile used in the code examples is as follows: Line 01 Line 02 Line 03 Line 04 Reproduce code: --------------- $file = 'test.csv'; $fp = fopen($file, 'r'); stream_filter_append($fp, 'convert.iconv.utf16/iso8859-15'); $line = fgets($fp); var_dump($line); $line = fgets($fp); var_dump($line); fclose($fp); $fp = fopen($file, 'r'); stream_filter_append($fp, 'convert.iconv.utf16/iso8859-15'); $line = fgets($fp); var_dump($line); fseek($fp, ftell($fp)); // this shouldn't move anything - but it does... $line = fgets($fp); var_dump($line); fclose($fp); Expected result: ---------------- string(8) "Line 01 " string(8) "Line 02 " string(8) "Line 01 " string(8) "Line 02 " Actual result: -------------- string(8) "Line 01 " string(8) "Line 02 " string(8) "Line 01 " string(4) " 01 " PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 19:00:01 2025 UTC |
Same issue with zlib: <?php $fh = fopen('php://temp', 'w+'); fwrite($fh, '123'); var_dump(ftell($fh)); stream_filter_append($fh, 'zlib.deflate', STREAM_FILTER_WRITE, 9); fwrite($fh, 'abc'); var_dump(ftell($fh)); fseek($fh, 0); var_dump(fread($fh, 1024)); fclose($fh); ?> Will return: int(3) int(3) string(3) "123" See: https://3v4l.org/VAfmR