Problems with file writing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
staar2
Forum Commoner
Posts: 83
Joined: Fri Apr 06, 2007 2:57 am

Problems with file writing

Post by staar2 »

I have problems with this function, it dosent want to work, it returns empty array.

Code: Select all

function deleteLine($line_num) {
			$content = $this->readFile();
			unset($content[$line_num]);
			
			$fp = fopen($this->filename, 'w+');
			
			flock($fp, LOCK_EX);
			foreach ($content as $line) {
				fwrite($fp, $line, 4029);
			}
			flock($fp, LOCK_UN);
			fclose($fp);
			
		}
:?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It doesn't "return" anything. How are you finding an empty array? The function result, if stored, would be null.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

You should use return true or false in this type of function.
Post Reply