g_p_java Posted February 1, 2009 Share Posted February 1, 2009 Hello i would like to read from a file.txt the fields it contains e.g. John teacher George doctor Maria lawer I have to read two strings which are seperated by a " " space. May you please tell me, how can i open and read the file? Thanks Link to comment https://forums.phpfreaks.com/topic/143404-how-do-we-read-two-fields-in-a-file/ Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 http://php.net/file http://php.net/explode Link to comment https://forums.phpfreaks.com/topic/143404-how-do-we-read-two-fields-in-a-file/#findComment-752215 Share on other sites More sharing options...
g_p_java Posted February 1, 2009 Author Share Posted February 1, 2009 i do: $filename = "/home/newfile.txt"; $file = fopen($filename, "r"); //fopen("c:\\data\\info.txt", "r"); fread($file, $rip." ".$rnewString . "\n"); fclose($file); i take : Warning: fread() [function.fread]: Length parameter must be greater than 0 What shall i correct? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/143404-how-do-we-read-two-fields-in-a-file/#findComment-752243 Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 You're using fread entirely wrongly. It takes a resource as the first parameter and a length in bytes as the second parameter. It then reads how ever many bytes you tell it to read from the resource. file() would be much easier to work with. Link to comment https://forums.phpfreaks.com/topic/143404-how-do-we-read-two-fields-in-a-file/#findComment-752257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.