|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-11-08 18:48 UTC] info at backups dot nl
Description: ------------ I get a fatal error on calling strrpos when the haystack is empty. I now have to check the haystack before calling strrpos, $haystack=''; $pos = strrpos($haystack, '.', -1); May other issue was brutally closed for replies. https://bugs.php.net/bug.php?id=80336 I don't understand why as the last answer given by you is incorrect. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 12:00:02 2026 UTC |
strrpos - appears to return the character after the found position (about 10% of the time in my example code: $find = 'Baden-Württemberg,"Karlsruhe'; $filename = 'data/sources/db-ip.com/dbip-city-lite.csv'; $f = fopen($filename,'r'); //stream_set_read_buffer($f,$b); $t1 = hrtime(true); do { $line = ffindline($f,$find); if ($line == false) break; echo '<br>'.$line; } while (true); $t2 = hrtime(true); $t = ($t2-$t1)/1000000; echo '<br> '.(number_format($t,10).'ms '); fclose($f); function ffindline($f,$find,$linefeed="\n") { $p = ftell($f); $b = 20000; //- block size, also must be bigger than largest line size do $data = stream_get_line($f,$b,$find); while (ftell($f)===($p+=$b)); if (feof($f)) return false; $p = strrpos($data,$linefeed); echo ' [found:'.urlencode(substr($data,$p,strlen($find))) .'] '; if ($p===false) echo 'ERROR'; fseek($f,$p-strlen($find)-strlen($data)-strlen($linefeed),SEEK_CUR); stream_get_line($f,$b,$linefeed); $data = stream_get_line($f,$b,$linefeed); return $data; }