sheraz Posted May 25, 2009 Share Posted May 25, 2009 sir i m trying to get data from a file but it is not working correctly.please tell me the solution. Here is the code. <? if(!($fp=fopen("abc.txt", "r")) ) die ("cannot connect to the file"); else { $lines[]=file("abc.txt"); foreach($lines as $line_num=>$lines) { echo $line_num; } } ?> i want the data written in file. but its output is 0. Link to comment https://forums.phpfreaks.com/topic/159611-php-file/ Share on other sites More sharing options...
will35010 Posted May 25, 2009 Share Posted May 25, 2009 You have to use the w option with fopen to write to the file. http://us3.php.net/manual/en/function.fopen.php Please use the code tags. Link to comment https://forums.phpfreaks.com/topic/159611-php-file/#findComment-841832 Share on other sites More sharing options...
wildteen88 Posted May 25, 2009 Share Posted May 25, 2009 $lines[] should be $lines And your foreach loop needs to be foreach($lines as $line_num => $line) { echo $line_num . ' = ' . $line; } Link to comment https://forums.phpfreaks.com/topic/159611-php-file/#findComment-841835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.