kid85 Posted December 29, 2007 Share Posted December 29, 2007 I'm using PHP5.2.4 and don't know which of the 2 methods is better or more standard. Any other suggestions would be great. I just need to open a file which is inside my server and search for 1 string using preg_match regex. I would need to read all of its contents no need to write anything. $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); // do regex stuff fclose($handle); Link to comment https://forums.phpfreaks.com/topic/83645-solved-fread-or-file_get_contents/ Share on other sites More sharing options...
tibberous Posted December 29, 2007 Share Posted December 29, 2007 file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance. Link to comment https://forums.phpfreaks.com/topic/83645-solved-fread-or-file_get_contents/#findComment-425510 Share on other sites More sharing options...
kid85 Posted December 30, 2007 Author Share Posted December 30, 2007 The file I need to read is not a database its just a normal web page. fread and preg_match could be discarded in favor of fscanf which combines both functions... is that correct ? Any idea of which functions would be faster ? Link to comment https://forums.phpfreaks.com/topic/83645-solved-fread-or-file_get_contents/#findComment-425570 Share on other sites More sharing options...
trq Posted December 30, 2007 Share Posted December 30, 2007 fread and preg_match could be discarded in favor of fscanf which combines both functions... is that correct ? Not at all. file_get_contents and preg_match are probably your best options. Link to comment https://forums.phpfreaks.com/topic/83645-solved-fread-or-file_get_contents/#findComment-425580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.