|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-09-10 22:28 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2020-09-10 22:28 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 13:00:01 2025 UTC |
Description: ------------ I am trying to insert a line in a file after a line that is searched for. The line to insert is inserted fine, but the text after it gets truncated partially. ********* test.txt ************ PHP is a great language. It is a tool for the ages. It is easy to use and fast too! Test script: --------------- $absoluteFilePath = '<your_root_path>/test.txt'; $splFile = new \SplFileObject($absoluteFilePath, 'c+'); $splFile->flock(LOCK_EX); $splFile->rewind(); // Add to next line. while ($splFile->valid()) { $currentLine = $splFile->fgets(); if (strpos($currentLine, "It is a tool for the ages.") !== false) { $splFile->fwrite("But it has a few bugs.\n"); } } $splFile->flock(LOCK_UN); Expected result: ---------------- PHP is a great language. It is a tool for the ages. But it has a few bugs. It is easy to use and fast too! Actual result: -------------- PHP is a great language. It is a tool for the ages. But it has a few bugs. ast too!